Wiki· Updated 19 Oct 2026
Cheat sheet: git
git: daily commands, branches, merge and rebase, undoing changes, tags, stash.
Every day
git status -sb
git diff # changed and not staged
git diff --staged # what goes into the commit
git add -p # stage piece by piece
git commit -m "Fix login redirect"
git pull --rebase
git push
git log --oneline --graph -20
git log -p -- path/to/file # history of a file
git blame -L 10,30 path/to/file
Branches
git switch -c feature/login # new branch
git switch main
git branch -a # all, including remote
git push -u origin feature/login # first push of a branch
git merge feature/login
git rebase main # move your branch onto a fresh main
git rebase --continue | --abort
git branch -d feature/login # delete a merged branch
git push origin --delete feature/login
git fetch --prune # drop remote branches that are gone
Undo
git restore file # discard changes in a file
git restore --staged file # unstage, keep the changes
git commit --amend # fix the last commit (before pushing)
git reset --soft HEAD~1 # undo a commit, keep the changes
git reset --hard HEAD~1 # undo a commit and its changes
git revert <sha> # undo a pushed commit with a new commit
git reflog # where did the commit go — find it
git reset --hard <sha-from-reflog>
git clean -fdn # what clean would delete (untracked)
git clean -fd
Put aside
git stash push -m "wip"
git stash list
git stash pop
git stash drop
Tags and releases
git tag -a v1.4.0 -m "v1.4.0"
git push origin v1.4.0
git tag -l "v1.*"
git describe --tags
Remotes
git remote -v
git remote set-url origin git@github.com:org/repo.git
git clone --depth 1 https://github.com/org/repo.git # no history
git cherry-pick <sha> # take one commit from another branch
Settings
git config --global user.name "Ivan Petrov"
git config --global user.email ivan@example.com
git config --global pull.rebase true
git config --global init.defaultBranch main
git config --global alias.lg "log --oneline --graph --decorate -20"
Committed a password by accident? Deleting the commit does not help — it stays in history and clones: change the password, then clean the history (git filter-repo).
