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>

GitHub CLI (gh)

Log ingh auth login
Clone repogh repo clone owner/repo
Create repo from current dirgh repo create my-app --private --source=. --push
Fork & clonegh repo fork owner/repo --clone
Create pull requestgh pr create --fill--fill uses commit messages for title/body; add --draft for a draft PR
PR with title & reviewergh pr create --base main --title "Add login" --body "Closes #12" --reviewer <user>
List pull requestsgh pr list
Check out a PRgh pr checkout <number>
View PRgh pr view <number> --web
PR checks statusgh pr checks
Merge PRgh pr merge <number> --squash --delete-branch
Create issuegh issue create --title "Bug" --body "Steps..."
Watch workflow rungh run watch

Git Flow & Branching Strategies

Git Flow branchesmain production releases develop integration branch feature/* from develop release/* from develop → main + develop hotfix/* from main → main + develop
Start feature (plain git)git switch develop git switch -c feature/login
Finish featuregit switch develop git merge --no-ff feature/login git branch -d feature/login
Releasegit switch -c release/1.2.0 develop # bump version, fix bugs git switch main && git merge --no-ff release/1.2.0 git tag -a v1.2.0 -m "v1.2.0" git switch develop && git merge --no-ff release/1.2.0
Hotfixgit switch -c hotfix/1.2.1 main # fix, commit git switch main && git merge --no-ff hotfix/1.2.1 git switch develop && git merge --no-ff hotfix/1.2.1
git-flow extensiongit flow init git flow feature start login git flow feature finish login git flow release start 1.2.0Requires the git-flow (AVH) tool
GitHub Flowgit switch -c feature/x main git push -u origin feature/x gh pr create --fillShort-lived branches off main, merged via PR, deploy from main
Trunk-basedgit pull --rebase origin main git push origin HEAD:mainSmall, frequent commits to main behind feature flags
Push tagsgit push origin --tags

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.