Git for Engineers — Level by Level›Level 1 · Cheat sheet & self-check

Level 1 — Foundations · wrap-up

Cheat sheet & self-check

Every command from this section on one page.

01 · How Git works

Set up once

git config --global user.name "Your Name"Name recorded in your commits
git config --global user.email you@example.comEmail recorded in your commits
git config --global init.defaultBranch mainNew repositories start on main
git config --global pull.rebase truegit pull rebases instead of creating merge commits
git config --list --show-originEvery setting and the file it comes from

Look inside

git init / git clone <url>Start a repository / copy an existing one
git log --oneline --graph --allThe commit graph with every branch
git cat-file -p HEADThe raw commit object: tree, parent, author, message
git cat-file -p HEAD^{tree}The snapshot (tree) that commit points to
git rev-parse HEADThe full SHA of the current commit
cat .git/HEADWhere HEAD points (usually a branch)

02 · The everyday workflow

See changes

git status -sbShort status with the current branch
git diffUnstaged changes
git diff --stagedWhat the next commit will contain
git diff main...featureWhat a branch changed since it split from main

Stage and commit

git add -pStage change by change (interactive hunks)
git commit -m "fix(api): return 404 for unknown order"Commit with a message
git commit --amendFix the last commit (only if not pushed yet)
git restore --staged <file>Unstage a file

Read history

git log --oneline -20Last 20 commits, one line each
git log -p -- path/to/fileEvery change to one file, with diffs
git log -S "max_connections"Commits that added or removed a string
git blame -L 40,60 app.pyWho last changed lines 40–60, and in which commit
git show <sha>One commit: message and diff

03 · Branching and merging

Branches

git switch -c feature/loginCreate a branch and switch to it
git switch mainGo back to main
git branch -vvLocal branches with their upstream and last commit
git branch -d feature/loginDelete a merged branch (-D forces)

Combine

git merge --ff-only feature/loginMerge only if it's a fast-forward
git merge --no-ff feature/loginAlways create a merge commit
git rebase mainReplay the current branch's commits on top of main
git rebase -i HEAD~4Reorder, squash or reword the last 4 commits

Conflicts

git statusLists conflicted files
git diff --name-only --diff-filter=UOnly the conflicted files
git add <file> && git merge --continueMark resolved and finish a merge
git rebase --continue / --abortContinue or cancel a rebase
git merge --abortCancel a merge and go back