2

Basic Git Commands

Reading Time: 6 minutes

I have consolidated the list of basic GIT COMMANDS which every developer & software tester should be aware of. This post doesn’t have all the GIT COMMANDS but instead have the most used & required one. Please share your valuable comments below


git –version

To retrieve the git version details


git config –global user.name “<Name>”

To set the name


git config –global user.email “<Email>”

To set the email


git help <verb> or git <verb> –help

Example: git help config or git config –help

To retrieve help for the command


git init

This command will initialise empty Git repository the folder & you will notice a file named .git in the folder. To uninitialise or stop watching this folder simply remove the .git file. This is now the working directory


git status 

To know the status of the git repository status


git pull

To pull the latest changes from the repository


Create a file .gitignore 

To make certain files to be ignored from tracking/included into the repository include the file names or wildcards like *.dll in the .gitignore file.

You can use notepad .gitignore if you are in windows

touch .gitignore if you are in linux


git clean -df

This will remove all the untracked files


git add -A

The command will include all the files which are modified/added/removed to the Staging Area


git add .gitignore

This command is for Staging specific file


git reset

This will remove all files from Staging Area


git reset .gitignore

This will remove the file from the Staging Area


git commit -m “<commit message>”

This will commit all the staged files to the local repository with commit message


git commit –amend -m “<commit message>”

This will update the previously committed message to a newer message


git log

This will show the list of commits made


git clone <url> <Directory location to clone>

This will clone the remote repository. In case if you are already in a directory then you can use the command like


git clone <url> .

Note: Including . (period) after the url will clone all the file extensions


git remove -v

To view the information about the remote repository


git branch -a

This is to view the list of branches


git branch

This will show you the sub branches under the already checked out branch


git diff

This will show the changes made to the repository


git pull origin <branch>

This will pull the changes from the branch


git push -u origin <branch>

This will push the changes to the remote repository


git branch <branch>

This will create new branch


git checkout <branch>

This will switch to the branch specified


git merge <branch>

This will merge the branch specified. Finally you need to the push the changes


git branch –merged

This will list down all the merges done so far


git branch -d <branch>

This command will delete branch from local repository


git push orgin –delete <branch>

This will delete the branch from remote repository

2 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.