Show Menu
Cheatography

Git Cheat Sheet Cheat Sheet (DRAFT) by

This is Git commands cheat sheet

This is a draft cheat sheet. It is a work in progress and is not finished yet.

Setup

To setup username and user email
$ git config --global user.name "­Exa­mpl­e"
$ git config --global user.email "­exa­mpl­e@g­mai­l.c­om"

Initialize the Git

 
$ git init : Initialize the Git

$ git clone <ur­l> : Copy the remote repository

Untracked, Staging, Tracked

 
git add <fi­len­ame> : Add a file to staging

git add . : Add all file to staging

git commit -m "­commit messag­e": Commit all staged file

git commit -am "­commit messag­e" : To add and commit together

git status : To view current status of file
 

Branches

 
git branch : View the all branches

git branch <br­anc­hna­me> : Create a new branch

git checkout -b <br­anc­hna­me> : Create a new branch and switch to it

git checkout <br­anc­hna­me>: Switch to a branch

git branch -d <br­anc­hna­me> : Delete a branch

Logs Check

 
git log : Check commits history in detail

git log --oneline : Shows commit history in one line

git diff : Shows changes in files

Merge Branches

 
If you want to merge branch A to B then,

git checkout B
git merge A

git rebase : It is also used to merge the branches but it is also merged the commit history.
 

Undo changes

 
git rm <fi­len­ame> : Remove a file from working directory

git rm --cached <fi­len­ame> : Remove from staging area

git revert <Commit ID> Reverting the commit

git reset <commit ID> It will delete all commits

Git/Github

 
git clone <ur­l> : Create a local copy of remote repo

git remote : To view the remote repo

git push : Push local changes to remote

git pull : Pull remote files to local.

Git cherry­-pick

 
If you only want a specific commit to merge in another branch then you can use it.

git cherry­-pick <commit ID>