Agile Testing, Automation, central repository, collabration, git, Maven, version control

Basic commands to start working with git.

In one of my previous blog, I have shared my experience why we need to use ‘Git’. In this post I will share basic commands to start with.

So lets get started.

To start with you need a machine where you want to use git. The choice would be of Windows, iOs, Linux, etc. The links would be same for different operating system, you just need to choose the one best fits your computer system.

For windows:

On your windows box download git , you can use these link:-


Once installed, type git in the windows search/start up window and you will see two options:-

  • Git GUI,
  • Git Bash.


Git Bash – will  give you Linux like environment where in you can work as an Linux operating system and perform git commands on bash.

Git GUI – window users who does not have linux box experience can use this to run git commands.

Other next thing you need to do is creation of account in github, or connecting with the git official repository. For this you need to simply sign up in After this , you can directly push all your code directly from your local and can work on multiple branches/repository as and when required.

Creating a repo

Create a new repository on the command line

git init
git add
git commit -m "first commit"
git remote add origin
git push -u origin master

Create a new repository from github account by clicking on new repository:-


Creating a new branch

git checkout -b <name-of-new-branch> 
Switched to a new branch 'name-of-new-branch>'

Switching to existing branch

git checkout <name-of-new-branch>

Deleting an existing branch

git branch -r
This will list all the existing branches of the current repo.

git branch -d <name-of-new-branch>
This will delete the branch from local

git branch -D <name-of-new-branch> 
This will delete the branch from globally

Cloning a repository

Go to github in browser , select the URL of the repo you need to clone as shown below:-


Cloning via command line

git clone <path-of-repo>


Initialising a repo

 Go to the folder where you have clone/downloaded the code, and hit init command
git init

Checking the local changes

 One can check status of code by this command
git status

Adding local changes:-

 One can add all the local changes by this command

git add .



Saving local changes:-

git stash

Committing a code snippet:-

One can commit in two ways:- One with commit message as shown below

git commit -m "message"


and other without commit message

git commit

Pushing the code to local and remote repository

git push origin 
before you create a new branch, make sure you do a
git fetch
that will pull the latest merge changes down for the develop branch

 Merging code to master from new branch

git fetch
git merge origin/master

1 thought on “Basic commands to start working with git.”

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s