All Cheat Sheets
Git Cheat Sheet
Essential Git commands for version control — branching, merging, rebasing, stashing, and more.
Setup & Init
Initialize repo
git initClone repo
git clone <url>Set user name
git config --global user.name "Name"Set email
git config --global user.email "email"Staging & Commits
Stage file
git add <file>Stage all
git add .Commit
git commit -m "message"Amend last commit
git commit --amendUnstage file
git reset HEAD <file>Branching
List branches
git branchCreate branch
git branch <name>Switch branch
git checkout <name>Create & switch
git checkout -b <name>Delete branch
git branch -d <name>Merging & Rebasing
Merge branch
git merge <branch>Rebase
git rebase <branch>Interactive rebase
git rebase -i HEAD~<n>Abort rebase
git rebase --abortContinue rebase
git rebase --continueRemote
Add remote
git remote add origin <url>Push
git push origin <branch>Pull
git pull origin <branch>Fetch
git fetchPush & set upstream
git push -u origin <branch>Stashing
Stash changes
git stashList stashes
git stash listApply stash
git stash popDrop stash
git stash dropLog & Diff
View log
git log --onelineGraph log
git log --graph --all --onelineDiff unstaged
git diffDiff staged
git diff --stagedUndo & Reset
Soft reset
git reset --soft HEAD~1Hard reset
git reset --hard HEAD~1Revert commit
git revert <hash>Discard changes
git checkout -- <file>GitHub CLI (gh)
Log in
gh auth loginClone repo
gh repo clone owner/repoCreate repo from current dir
gh repo create my-app --private --source=. --pushFork & clone
gh repo fork owner/repo --cloneCreate pull request
gh pr create --fill--fill uses commit messages for title/body; add --draft for a draft PRPR with title & reviewer
gh pr create --base main --title "Add login" --body "Closes #12" --reviewer <user>List pull requests
gh pr listCheck out a PR
gh pr checkout <number>View PR
gh pr view <number> --webPR checks status
gh pr checksMerge PR
gh pr merge <number> --squash --delete-branchCreate issue
gh issue create --title "Bug" --body "Steps..."Watch workflow run
gh run watchGit Flow & Branching Strategies
Git Flow branches
main production releases
develop integration branch
feature/* from develop
release/* from develop → main + develop
hotfix/* from main → main + developStart feature (plain git)
git switch develop
git switch -c feature/loginFinish feature
git switch develop
git merge --no-ff feature/login
git branch -d feature/loginRelease
git 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.0Hotfix
git 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.1git-flow extension
git flow init
git flow feature start login
git flow feature finish login
git flow release start 1.2.0Requires the git-flow (AVH) toolGitHub Flow
git switch -c feature/x main
git push -u origin feature/x
gh pr create --fillShort-lived branches off main, merged via PR, deploy from mainTrunk-based
git pull --rebase origin main
git push origin HEAD:mainSmall, frequent commits to main behind feature flagsPush tags
git push origin --tagsFree 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.