Git Commands Cheatsheet

Repository

git initInitialize new repository
git clone Clone remote repository
git remote add origin Add remote origin
git remote -vList remotes

Staging & Commits

git add .Stage all changes
git add -pInteractive patch staging
git commit -m 'msg'Commit staged changes
git commit --amendAmend last commit
git reset HEAD Unstage a file
git stashStash uncommitted changes
git stash popApply last stash

Branches

git branchList branches
git checkout -b Create and switch branch
git switch Switch branch (modern)
git merge Merge branch into current
git rebase Rebase onto branch
git branch -d Delete merged branch

Remote

git fetchFetch remote changes
git pullFetch + merge
git push origin Push to remote
git push --force-with-leaseSafe force push

History

git log --oneline --graphVisual commit history
git diffShow unstaged changes
git diff --stagedShow staged changes
git blame Show who changed each line
git bisect startBinary search for bug