GIT for Noob

G

GIT is a distributed version control system which is widely used in the day to day development activities. If you are student or a noob in software industry you will seriously need this blog, because here we are gonna see from the basics to intermediate usage of GIT in the development which will help you to understand and implement by yourself while you are into the development activities.

Version Control

Version control is the process of tracking changes of the files and file contents. It keeps a HEAD version (last known changes of file contents / files) and compare it with the new changes and also keeps track of all the past and future changes of the files and file contents.

Most of the companies looking out for the developers who have knowledge on GIT commands. So its better to get hands-on with commands instead of using the GIT tools

Git is an application software so we must install it before getting started, Git is available on windows, linux and mac. Check this link to download and install the Git in your local / server machine.

Before jumping on to the GIT implementations, lets be clear on some basics.

Repository – It is the folder . git which will create when we initialize a project using git init command. This folder tracks all the files changes happening in the project (current location) Each repository holds multiple branches.

Branches – In Git, the branches are unique pointer which will keep track of the changes. We can create different branches for keeping the file changes related feature, bugfix or according to environment dev and prod. The developer holds the responsibility of maintaining the branches which is created by them. Branch names must be unique and we can move code from one branch to another branch by raising a pull request / merge request

Commits – When the developer is ready to add the new changes into the remote repository or into his feature branch. He must add the changed files to stages then commit with proper commit message and then it will be pushed to repo branch and it can be pulled by other team members.

GIT with SOURCE CODE MANAGEMENT TOOL

There are variety of source code management tools available in market (as cloud services), some of the major tools like github, gitlab and bitbucket which utilizes the power of GIT to manage the project source codes and also provide the better way to collaborate and code along with the team members. So never compare or get confused with Git and Github or other SCM cloud services.

So now we have an understanding that without Git there is no services like Github, Gitlab and Bitbuckets. Lets see the structure and flow of how the git works from the local to its remote repositories in the Github as an example.

Consider here the remote repository is Github having the project source code. Developer A is the existing employee of the company and Developer B is the new resource onboarded into the project and got access to the Github repository.

Scenario : Developer B want to setup his local environment

To setup the local environment, the developer B must have already installed the GIT software in his local machine, if it is already installed then get the repository link. It will be like https://github.com/user/repo.git (HTTPS) or git@github.com:user/repo.git (SSH) for this example we will go with HTTPS.

1. Create a local copy of the Github (remote) repository code

git clone https://github.com/user/repo.git

2. Change the default branch to Developer B branch

git fetch 
git checkout developerb

3. Developer B local setup is ready to push his local changes to remote repository, the below are the basic commands

git diff - to check the local changes
git add . - to stage all changes for commit
git add file - to add a particular file to stage
git commit -m "commit message" = to add a commit message
git push origin branchname - to push the current commits into the remote branch
git pull origin branchname - to pull the changes from remote of current branch or specified branch

There are lot of Git commands available and it can be used upon the developer needs. Hope you got an understanding about what is GIT and how to use it. If you have any other scenario in mind and you wanted to know the commands please comment it, we will discuss on the same.

4 Comments

  • I have been browsing on-line more than three hours as of late,
    yet I by no means found any attention-grabbing article
    like yours. It is beautiful value enough for me.
    In my view, if all site owners and bloggers made excellent content as you probably did, the web will probably be
    a lot more useful than ever before.

    • This really encourages me to write more blogs, please feel free to comment if you need blog on any topics now or later any time.

By Mano

Get in touch

Let me know on Class room, if any topic which you looked out here is not available, I will make sure that will be there for you on next visit.