The commands you need every day, grouped. Undoing and rescuing lost work is separate — Undo in git; finding where it broke — Find where it broke.
What’s going on
Command
What it does
git status -sb
changes in short form, and how far behind origin you are
git diff
edits not yet added to the index
git diff --staged
what goes into the next commit
git diff main..traefik-timeouts --stat
how a branch differs from main, by file
git log --oneline -10
the last 10 commits, one line each
git log --oneline --graph --all -20
a graph of every branch
git show HEAD
what’s in the last commit
git log -p --follow -- traefik/data/traefik.yml
one file’s history with its edits, including before a rename
The first line of git status -sb is ## main...origin/main [ahead 1, behind 2]: one of your commits isn’t pushed,
and two from GitHub haven’t been pulled.
Committing
Command
What it does
git add traefik.yml
a file into the index
git add -p
into the index piece by piece, with a prompt for each
the editor shows the whole diff while you write the message
git commit -am "…"
add changed files and commit; new files won’t be included
The message is “where: what was done — why”. The first line stays under 72 characters: log --oneline and GitHub
show it. “fix”, “changes”, “wip” will say nothing a month from now.
Branches
Command
What it does
git branch
local branches; * marks the current one
git branch -a
plus the branches on origin
git switch main
switch to a branch
git switch -c fix-crowdsec-hooks
create a branch and switch to it
git switch -
back to the previous one
git branch -m new-name
rename the current one
git branch -d fix-crowdsec-hooks
delete a merged one; -D deletes any
git push origin --delete fix-crowdsec-hooks
delete a branch on GitHub
Syncing
Command
What it does
git fetch
get what’s new from origin, changing nothing locally