Show Menu
Cheatography

Git-Bash Cheat Sheet (DRAFT) by

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

Glossary

[value]
Optional value
value
User-d­efined value
<re­f>
SHA-1 reference to commit or tag
<pa­ths>
List of paths/­wil­dcards to match files
git --help glossary
Git vocabulary

Init Repository

Create new git repository in current folder
git init
Create a copy of git repository by given url
git clone https:­//r­epo­sit­ory.git
List remote reposi­tories
git remote -v
Create alias origin for remote repository
git remote add origin https:­//r­epo­sit­ory.git
Change url of remote repository with alias origin
git remote set-url origin https:­//r­epo­sit­ory­-2.git
Manage remote reposi­tories
git repository --help

Branching

Create new branch
git checkout -b branch­-name [<c­omm­it>] // -B to override existing branch
Switch to existing branch
git checkout branch­-name
Remove branch
git branch -d branch­-name // Use -D or -df to force
Rename current branch
git branch -m new-br­anc­h-name
List branches
git branch --list [pattern] // -r (remote) -a (all) -v (show last commit) 
// --contains <co­mmi­t> (contains specified commit)
// --merged (can be safely removed) --no-m­erged (may need attention)
Create branch without commits history
git checkout --orphan -b branch­-name [<c­omm­it>]
More actions with branches
git branch --help 
git checkout --help

Utilities

 

Tricks

 

GUI

 
 

Commit Changes

Add selected files to staging (prepare to commit)
git add <pa­ths> // '.' will match all unstaged files
Describe current state of local repository
git status
Make commit with message
git commit -m "message"
Make commit and append it to previous one
git commit --amend
Make commit and append it to previous one with new message
git commit --amend -m "message"

Undo Changes

Get the previous version of a given files
git checkout <co­mmi­t> <pa­ths> // HEAD is used implicitly if <co­mmi­t> omitted
Revert certain commit by applying another one (to persist history)
git revert <co­mmi­t>
Unstage files
git reset <pa­ths>
Unstage all files
git reset
Move state to specified commit
git reset <co­mmi­t> 
// --hard (to remove changes) --soft (to leave changes staged)
Set specified files to state of certain revision
git checkout <co­mmi­t> <pa­ths>

Exchange with Remote

Fetch
git fetch
Pull
git pull
Push
git push

Difference and Merge

 

Hide Changes

 

Watch History

 

General Configs

 

Revisions

HEAD
Reference to last commit in current branch
<co­mmi­t>^
First parent of selected commit
<co­mmi­t>^^
Second (and so on) parent of specified commit
<co­mmi­t>~n
N-th parent of selected commit (e.g. ^2)
<co­mmi­t1>..<­com­mit­2>
git --help revisions
More git revision syntax here

Advanced Configs

 

Links

 

Tips

 

Use Cases

Remove all the local updates
git reset --hard

git clean -f