Version Control and Basic Git and GitHub (for beginners)

As a developer or even as a tech savy person we should know what is version control. It really eases our life from maintaining school projects to managing big codebases.

In this blog basics will be discussed then in next blog advance commands will be covered.

Problems

When a programmer/developer starts his journey he use to keep all the programs and codes in a folder with a specific name in his disk. But after somedays he thinks of updating the code he again open that code and make some changes in that or copy the app then make some changes in that copy. Very Simple and relatable😅. Ya I also used to do it.

But lets think of some edge cases here of what things can happen in this phase.

  • Everyone likes to have different versions of their app like v1 or v2. So if the app is very large in size and making copies will consume disk space.

  • While updating the code if copy not made and we have made many changes in the code it's become very frustrating to delete all the code and write them from beginning. In big codebase it is nearly impossible.

  • Also if suppose our disk gets corrupted we will loose our all data.

Version control solves all this problem. All of the things discussed above are the tensions during development phase of any application. 


Version Control

Version Control is nothing but a practice or technique use to maintain your work and even your data (some extent). 

Version control software keeps track of every modification to the code in a special kind of database. If a mistake is made, developers can turn back the clock and compare earlier versions of the code to help fix the mistake.

Basically only changes made from one version to another are saved not the whole code in this practice.

So no need to make multiple copies or no need to delete the whole codebase and modifications. You can rectify them with some single commands.

Generally we call each project folder a repository or repo . 

Generally we use to maintain a local repo that is present in our system and maintained using any version control tool like git . 

Another online repo is maintained in platform like github. We can copy the entire online repo with just come commands of git.


Git

Git is nothing a version control tool. We have both git cli and git gui . But as a programmer we should know git cli first. Basically the cli is known as git bash. So we can even use bash scripts for automating the stuffs but that will be discussed latter.

Terminologies of git and its different spaces

  • Working directory is the folder where we work with the code. Here the code of files are not tracked. Just which are added are just observed.
  • Staging area is the space where actually every code is observed. We need to add our files to staging area from working directory first to observe them.
  • Repository is the final area where the current stage of code will be saved if you want. We call this as commit . Commit is basically adding the files from staging area to repository. 
  • Checkout is basically taking files from repository to working directory

Well I know the concept is not clear at all by listening the terms 😣. So lets make it clear by practically using git and it's commands😀. 



Setup Git

It is very to setup git. Just type download git in google and go with next next in the setup.

Basic Git Operations Step wise

First open the project folder then right click then open git bash. Use git config command to configure the username and email. Then use the below commands.
  • To initialise git in a project

        To setup a git to observe your project this is necessary.

     git init
  • To add files to staging area 

        Lets add all the files to the staging area to observe changes.

     git add .
     Lets add a specific file to the staging area to observe changes.
     git add filelocation
  • To commit files 

        To commit files to save to repository. Files must be added to staging area first then they can be commited only

     git commit -m "Commit Message"
     So upto this we made a workflow. 

    These four commands are the basic 4 commands. Although they are not enough in some scenario.


  

GitHub

Now it is not enough to save everything offline. So its better to push your repository or the things that are commited online in a platform like github. GitHub even plays a big role in deployment.

It is very simple to use.


For using github first create an account in github.

  • Connecting git and github(beginner friendly way)
           Now to use git and github we need to connect them . Basically we connect git with a specific repo/project of github. 
    • Create a repo in github.
    • Copy the http url of the repo.
    • Then run the commands below
     git remote add URL-COPIED
     git remote add origin
     git push -u origin
 The last step is basically putting your repo data to the url.

Hope it generated some values. I know I have listed only some commands but please get habituated to them to master and understand other commands as well.

If any problem occurs just google them. You will get the solution.

Topics such as branch , stash and other commands will be discussed surely in next episode 👍.

Keep coding ♥

Comments

Post a Comment

Popular posts from this blog

React States Vs React Refs f. What? When? Why? How?