This cheat sheet features the most important and commonly used Git commands for easy reference.
☑️ CREATE
For Existing Data
cd ~/Projects/MyProject
git init
git add .
From Existing repo
git clone ~existing/repo ~/new/repo
git clone you@host.in:dir/project.git
default protocol is ssh
☑️ UPDATE
Fetch Leatest Change From Origin
git fetch
this does not merge them
Pull leatest chage from origin
git pull
does a fetch followed by a merge
Apply a Patch that someone sent you
git am -3 patch.mbox
In case of conflict, resolve the conflict and
git am --resolve
☑️ PUBLISH
Git commit all local change
git commit -a
Git commit with message
git commit -m 'message'
Preapre a patch for other developers
git format-patch origin
push change to origin
git push [origin] [branch]
Make a version or milestone
git tag <vesrion_name>
Push the tag
git push origin Tagname
Push All tag
git push origin --tags
Delete tag
git tag -d <Tagname>
☑️ BRANCH
Switch to the BRANCH branch
git checkout <BRANCH>
Merge branch B1 into branch B2
git checkout <B2>
git merge <B1>
Create branch based on HEAD
git branch <BRANCH>
Create branch based on another
git checkout <new> <base>
Delete Branch
git branch -d <branchName>
☑️ REVERT
Return to the last committed state
git checkout -f | git reset --hard
youcannot do the hard reset
Revert the last commit
git revert HEAD
create a new commit
Fix the last commit
git commit -a -amend
after editing the broken files
Checkout the ID version of file
git checkout <ID> <file>
☑️ SHOW
File changed in working directory
git status
Change to tracked files
git diff
Change between ID1 and ID2
git diff <ID1> <ID2>
History of change
git log
History of change with files changed
git whatchanged
Who Changed what and when in a file
git blame <file>
A commit identifyby ID
git show <ID>
A specific file from a specific ID
git diff <ID>:<FILE>
All local branched
git branch
star "*" mark the current branch
Search for patterns
git grep <pattern> [path]
Top comments (0)