Show Menu
Cheatography

Git Cheatsheet Cheat Sheet (DRAFT) by

Git related sheets. Terminal based.

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

Commits

git commit -m "­msg­"
Commit staged with message
git commit -a -m -"ms­g"
Stage and commit all tracked files
git log
Commit history
git dff
Show unstaged changes
git diff --staged
Show staged changes

Branches

git branch
List branches
git branch <na­me>
Create new branch
git checkout <b>
Switch to branch <b>
git merge <b>
Merge <b> into current one
git branch -d <n>
Delete branch <n>
 

Termin­ology

Staging Area
Where files go before commit (git add)
Commit
Snapshot of staged changes
Branch
A separate line of develo­pment
Merge
Combines changes of two branches
Remote
A copy of repo hosted elsewhere
Clone
Local clone of remote repo
Pull
Download and merge remote changes
Push
Upload your commit to remote

Tracking File

git add <f>
Stage a file for commit
git add .
Stage all files
git restore --staged <f>
Unstage a file
git reset <f>
Unstage but keep working changes
git rm <f>
Delete tracked file and stage removoval
 

Fixing mistakes

git restore <f>
Revert file to last commited state
git reset --soft HEAD~<­n>
Undo last n commit, keep changes staged
git reset --hard HEAD~<­n>
Undo last commit and discard changes
git stash
Tempor­arily save uncomm­itted changes
git stash pop
Re-apply stashed changes
git reflog
See all recent HEAD changes

Remote

git remote -v
List remotes
git remote add origin <ur­l>
Add a remote named "­ori­gin­"
git push -u origin <br­anc­h>
Push and set upstream branch
git push
Push commits to remote
git pull
Fetch and merge from remote
git fetch
Download latest changes without merging