Git cheat sheet

Git cheat sheet

We all use Git but its really painful to learn all the commands. Trying to provide few important commands to help you reduce the effort.

Config git user and email

git config --global user.name "John Snow"
git config --global user.email [email protected]

Clone a repo

git clone [email protected]{git server}:{repo}

Check the status of files

git status 

Add files to git

 git add {directory}/{file name} 

Commit file to tracked files

 git commit -m "your commit message" 

Push your changes to git server

 git push origin {branch name} 

Pull the latest code from the repo

 git pull origin {branch name} 

Delete all your local changes

 git stash 

Create a branch

 git checkout -b {branch name }

Check out a branch

 git checkout {branch name} 

Check out a specific file from a commit id

 git checkout {commit id} {file to restore}

Discard all your local changes

 git reset --hard HEAD

Check git history

git log 

To check the who made what changes

 git blame {file name} 

Leave a Reply

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