Skip to content

/cheatsheets/git/git-cheat-sheet

Git cheat sheet: everyday commands

verified onenvironmentlocal · windows 10.0.26200 arm64 · GNU bash 5.3.15 (Git Bash) · git version 2.55.0.windows.5updated 2026-10-20
tool
Git
versions
Git 2.23+
os
linux, macos, windows

The Git commands for daily work. git switch and git restore (Git 2.23+) replace the overloaded git checkout for branches and files.

A typical session

bash
git init -q -b main demo && cd demo
echo "hello" > README.md
git add README.md && git commit -qm "Add README"
git switch -q -c feature/greeting
echo "world" >> README.md && git commit -qam "Extend greeting"
git switch -q main && git merge -q --no-edit feature/greeting
git log --oneline --graph --all

Output

* 37042af Extend greeting
* 74c3f75 Add README

Setup

CommandWhat it does
git config --global user.name "Name"identity for commits
git config --global init.defaultBranch mainbranch name for new repositories
git initcreate a repository in the current folder
git clone <url> [dir]copy a repository with its history

Stage and commit

CommandWhat it does
git status -sbshort status with branch
git add <path> / git add -pstage a file / stage hunk by hunk
git commit -m "msg"commit the staged changes
git commit --amendrewrite the last commit (message or content)
git diff / git diff --stagedunstaged / staged changes

Branches

CommandWhat it does
git switch -c <branch>create and switch
git switch <branch>switch to an existing branch
git branch -d <branch>delete a merged branch
git merge <branch>merge into the current branch
git rebase <base>replay the current branch on top of base

History

CommandWhat it does
git log --oneline --graph --allcompact graph of every branch
git log -p <path>history of a file with diffs
git show <commit>one commit in detail
git blame <path>last change for each line

Undo

CommandWhat it does
git restore <path>discard unstaged changes in a file
git restore --staged <path>unstage, keep the changes
git reset --soft HEAD~1undo the last commit, keep changes staged
git revert <commit>new commit that undoes an old one (safe after push)
git reflogevery position HEAD has had; recover "lost" commits

Stash, remotes and tags

CommandWhat it does
git stash / git stash popshelve and re-apply uncommitted work
git remote -vlist remotes
git fetch / git pull --rebasedownload / download and rebase onto it
git push -u origin <branch>push and set upstream
git tag -a v1.0 -m "msg"annotated tag
git push origin --tagspush tags

Sources