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>