High-frequency Git command reference.
Basic commits
git status # check status
git add . # stage
git commit -m "feat: ..." # commit
git log --oneline -10 # recent commits
git diff # unstaged changes
git diff --staged # staged changes
Branches
git branch # local branches
git branch -a # all branches
git checkout -b feature # create and switch
git switch feature # switch
git branch -d feature # delete merged branch
git merge feature # merge
Undo
git restore file.txt # discard working-tree changes
git restore --staged file # unstage
git reset --soft HEAD~1 # undo commit, keep changes
git reset --hard HEAD~1 # undo commit and discard changes (careful)
git commit --amend # edit last commit message
Remotes
git remote -v # list remotes
git remote add origin <url> # add a remote
git push origin main # push
git pull # pull
git fetch # fetch only, no merge
git push --force-with-lease # safe force push
Rebase
git rebase main # rebase current branch onto main
git rebase -i HEAD~3 # interactive: clean up last 3 commits
git pull --rebase # pull with rebase (linear history)
Tags
git tag v1.0.0 # create a tag
git tag -a v1.0.0 -m "..." # annotated tag
git push origin v1.0.0 # push a tag
git tag -d v1.0.0 # delete a local tag
Search
git log -S "keyword" # commits that added/removed a string
git blame file.txt # line-by-line attribution
git show <commit> # inspect a commit
Stash
git stash # stash changes
git stash pop # restore
git stash list