All Cheat Sheets

Git Cheat Sheet

Essential Git commands for version control — branching, merging, rebasing, stashing, and more.

Setup & Init

Initialize repogit init
Clone repogit clone <url>
Set user namegit config --global user.name "Name"
Set emailgit config --global user.email "email"

Staging & Commits

Stage filegit add <file>
Stage allgit add .
Commitgit commit -m "message"
Amend last commitgit commit --amend
Unstage filegit reset HEAD <file>

Branching

List branchesgit branch
Create branchgit branch <name>
Switch branchgit checkout <name>
Create & switchgit checkout -b <name>
Delete branchgit branch -d <name>

Merging & Rebasing

Merge branchgit merge <branch>
Rebasegit rebase <branch>
Interactive rebasegit rebase -i HEAD~<n>
Abort rebasegit rebase --abort
Continue rebasegit rebase --continue

Remote

Add remotegit remote add origin <url>
Pushgit push origin <branch>
Pullgit pull origin <branch>
Fetchgit fetch
Push & set upstreamgit push -u origin <branch>

Stashing

Stash changesgit stash
List stashesgit stash list
Apply stashgit stash pop
Drop stashgit stash drop

Log & Diff

View loggit log --oneline
Graph loggit log --graph --all --oneline
Diff unstagedgit diff
Diff stagedgit diff --staged

Undo & Reset

Soft resetgit reset --soft HEAD~1
Hard resetgit reset --hard HEAD~1
Revert commitgit revert <hash>
Discard changesgit checkout -- <file>

Free tools for this

Keep the references coming

One email a week: new and trending developer tools, fresh comparisons, and what shipped. Unsubscribe in one click.