All You Need To Know About GIT

GIT is a repository (the place where the project is stored) and it’s an open-source software used for version control

What is Version Control?

The code which is stored in the GIT repository will undergo many code changes whether by a single developer or multiple developers. So Version control help in handling this by maintaining a history of what code changes have happened.

Why Version Control is needed for a Developer?

Real-life projects will have multiple developers working parallel. The version control system like Git is responsible to avoid or ensure that there are no code conflicts between developers and also developers can go back to the older version.

Let’s get started with GIT

Download GIT Setup
Download Git for OSX
Download Git for Windows
Download Git for Linux

After Downloading and Installing GIT in your local machine check for the GIT version
Command to check GIT version
Git –version

Now create a project folder in your local directory
Example: HelloGit
Once you created the local directory perform git init command to create a new git repository

Now will create a text document example: Demo.txt

Add a simple text like “Hello GIT”

Now your local repo consists of three trees maintained by GIT
Working Directory – will have actual files
Index – acts as staging are
Head – points to the last commit

What is the Staging area in GIT?

The staging area is used to keep track of all the file which are to be committed.
Command for staging single file

git add Demo.txt

The command for multiple file staging:

git add file1 file2 file3

Command to add all the file inside the folder to staging area

git add

What is the Commit process in GIT?

Commit operation is used when you commit your code, the code will be added to the local repository.
Before you commit the code, it should be in the staging area. If the file/code is not in staging area you can’t perform commit operation.

Command to commit:

git commit -m “[add commit message as per you wish]”

Now modify the text file

GIT Status –used check the status like what file is modified and what file are in staging

git commit -m “[add commit message as per you wish]”

The status shows that demo.txt is modified and is not yet in the staging area.

Now let us add demo.txt to the staging area and commit it using the following commands:

git commit -m “[add commit message as per you wish]” git commit -m “


Use to display all the commits which are done.

git commit -m “[add commit message as per you wish]”

Next will look on to GIT Branches

What is Branch in git?

Its a pointer to the latest commit.
Branches are used to develop features isolated from each other.
the master branch is the “default” branch when you create a repository.
Use other branches for development & merge them to the master branch.

Why we need multiple branches?

It support multiple parallel developments.
Until now we didn’t create any branch in GIT. So all the commit will go to master branch.

How to create Branch in GIT?

the command to create a new branch with name “dev1”

git branch dev1

the command to switch to dev1 branch from master branch

git commit -m “[add commit message as per you wish]”

the command to list out all branches

git branch

Let we do some new commits in the new branch

Verify GIT commit using “git log


To move the commit code from all the branch to master branch git merge is used

Command to merge the branch code to Master branch

First, go back to Master Branch

Then run git merge dev1 command

Remote Git Repository

Till now, we have been working only in the local repository. But in real life project each developer will work in their local repository, they will push the code into a remote repository.

Once the code is in the remote repository, other developers can see and modify that code.

Command to Connect to Remote Repo from Local Repo


git remote add origin [repository url]

Command to Push all the code from Local Repo to Remote Repo

git push -u origin master

Command to Pull the latest commit from Remote Repo to Local Repo

git pull origin master

Command to Clone Remote Repo in Local Repo

git clone [repository url]

You May Also Like

About the Author: admin

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.