A Brief Introduction To Basic Git Command

Posted By Gopal Tanwar | 31-May-2018

In this blog, we'll discuss some basic and essential commands of git.

Install Git (minimal required packages)

On Linux:
* For Redhat Based Distros:
$ sudo yum install git

* For Debian Based Distros:
$ sudo apt-get install git

On mac/windows:
*go to link: http://git-scm.com/download/linux
*download binaries and install using guided


a. To get clone from repo
    -    git clone <repo URL from git>

b. Now modify some code 

    -    After modify we have to check our changes so for this type the below command

        -    git status

    -    By the git status command, it will show you all file name in which you made the changes.

c. After seeing changes we have to commit our changes, so before commit, we have to add our code.
d. To add our code we have to follow the below command

    -    git add <file name>


    -    git add -A

In the first command, it will add only the file which we mention and in second command it will add all files in which we did changes.

e. After add, we have to commit the code to commit just follow the below command

    -    git commit -m "message to remember your changes"

f. Now we have to just push our code on git but before push first takes pull from the git, as if any other developer push there code on git by pull command we take all the updated code and after this, we push our code, so follow the below commands for pull and push.

    -    git pull origin < your branch name>

        - It will ask your username and password of git.
    -    After pull now we have
push our code by below command

            -    git push origin < your branch name> 

g. How to create a new branch from existing branch 

    -    By default if we create a new branch it will go under master branch for this command is 

            -    git checkout -b <branchname>

    -    If you want to create a new branch under existing branch for this command is 
            -    git checkout -b <yourbranchname> <existingbranchname>

h. You can switch from one branch to another by the below command.

    -    git checkout <branchname>

i. List all of your branches in your repo, and also check your current branch:

    -    git branch

j. After creating new branch we have to push it on the remote repo, so any other developer in your team can use it.

    -    git push origin <branchname>
k.  How to rename an existing branch

    -    There are two ways to rename a branch first if you are on the same branch which you want to rename then follow the command

            -    git branch -m <new-name>

    -    If you are on some other branch then follow the below command

            -    git branch -m <old-name> <new-name>

After above step, we have to delete the old-name remote branch and push the new-name local branch by below command

            -    git push origin :old-name new-name

After deleting the old name branch final step is to push the rename branch as follows

            -    git push origin -u new-name


Related Tags

Related Blogs

An Introduction About Non Functional Testing
Neha Saini | 23-May-2018
Here Is An Overview About Specflow
Smita Gupta | 18-Jun-2018
Explain Fluent Wait In Selenium Webdriver
Mohd Sheemal | 13-Jun-2018
Overview of Behavior Data Driven
Smita Gupta | 22-May-2018
What is API And What is Rest And Soap API
Himanshu Shukla | 22-May-2018
What is Agile Delivery
Anjali Pandey | 31-May-2018
An Introduction About Spike Testing
Neha Saini | 11-Jun-2018
Logging Infrastructure in Python
Rohitesh Rawat | 29-Jun-2018
Roles And Responsibilities Of A QA Leader
Suraj Mishra | 31-May-2018
Structure Based Testing Techniques
Divya Varnwal | 26-May-2018
Scrolling a Web Page Up or Down using Selenium WebDriver
Neha Dahiya | 07-Jun-2018
Request for Proposal

Recaptcha is required.

Sending message..