GitCheatsheet

Git - daily commands and how to undo things.

Everyday
  git status
  git add file.py            git add -p      (stage hunks interactively)
  git commit -m "message"
  git log --oneline --graph --decorate -20
  git diff                   unstaged changes
  git diff --staged          staged changes

Branches
  git switch -c feature      create and switch
  git switch main
  git branch -d feature      delete a merged branch
  git merge feature
  git rebase main            replay current branch on top of main

Remotes
  git clone URL
  git fetch                  download without merging
  git pull --rebase          fetch, then rebase local commits on top
  git push -u origin feature first push of a new branch

Undoing things
  git restore file.py                   discard unstaged changes to a file
  git restore --staged file.py          unstage, keep the changes
  git commit --amend                    fix the last commit message or contents (before pushing)
  git reset --soft HEAD~1               undo last commit, keep changes staged
  git reset --hard HEAD~1               undo last commit and DISCARD its changes
  git revert <commit>                   new commit that undoes an old one (safe after pushing)
  git reflog                            find "lost" commits after a bad reset

Stash
  git stash        git stash list        git stash pop

Inspecting
  git blame file.py
  git show <commit>
  git log -S "text"                     commits that added or removed "text"

.gitignore examples
  __pycache__/
  *.pyc
  .env
  node_modules/

Dick - 2026-10-31 02:07:44 UTC

I'd like to add something to the cheat sheet. How do I do that?
Name (optional):

Or: /edit?page=GitCheatsheet&text=your+text&name=YourName


Index | Recent changes | permalink | rev 6e03165335ea