Reference
Branch cheat sheet
The commands from the course, grouped by what you are trying to do. Git 2.56 · gh 2.100.
GitHub flow: create a branch → make changes → create a pull request → address review comments → merge your pull request → delete your branch (GitHub Docs).
See where you are
| Command | What it does | Lesson |
git status | Current branch, whether it is ahead of its upstream, uncommitted changes. | 2 |
git branch | List local branches; * marks the one HEAD is on. | 2 |
git branch -vv | Each branch's last commit, its upstream, and ahead/behind counts (docs). | 4 |
git branch -a | Local and remote-tracking branches (origin/…). | 4 |
git log --oneline --graph --all | The whole commit graph, one line per commit, with branch labels. | 2 |
Create & switch
| Command | What it does | Lesson |
git switch -c NAME | Create a branch at the current commit and switch to it — the everyday command (docs). | 2 |
git switch NAME | Move HEAD to an existing branch; the working tree is updated to match. | 2 |
git switch - | Jump back to the previous branch. | 2 |
git branch NAME | Create a branch but stay where you are. | 1 |
git checkout -b NAME | Older equivalent of switch -c; you will see it in tutorials and agent output. | 2 |
Compare
| Command | What it does | Lesson |
git diff main...feature | Three-dot diff: only what feature changed since it left main — what a PR shows (docs). | 2 |
git log --oneline main..feature | Commits on feature that are not on main. | 2 |
git merge-base main feature | Print the merge base: the commit where feature split from main (docs). | 10 |
git diff main..feature | Two-dot diff: how the two tips differ right now. Work that landed on main after the split shows reversed. | 10 |
git log --oneline HEAD..origin/main | After git fetch: commits on origin/main that your branch lacks. Any output means a stale branch. | 11 |
gh pr diff · --name-only | The current branch's PR diff, or just the changed file names. | 6 |
Merge & clean up
| Command | What it does | Lesson |
git merge NAME | Bring NAME into the current branch: fast-forward if possible, otherwise a merge commit (docs). | 3 |
git merge --no-ff NAME | Always create a merge commit (what GitHub's "Create a merge commit" does). | 3 |
git merge --abort | Mid-conflict: give up and restore the pre-merge state. | 3 |
git branch -d NAME | Delete a branch — refused unless it is fully merged (safe). | 3 |
git branch -D NAME | Force-delete, merged or not — throws the work away. | 3 |
git push origin --delete NAME | Delete the branch on GitHub (removes the pointer only). | 4 |
git branch --delete-merged PATTERN | New in Git 2.56: delete local branches already merged into their upstream (docs). | 4 |
Conflict markers
<<<<<<< HEAD
df = df.dropna() # your side (current branch)
=======
df = df.dropna(subset=cols) # their side (branch being merged)
>>>>>>> clean-data
Edit into the version you want, delete all three marker lines, then git add FILE and git commit (or git merge --continue) (docs).
Remotes
| Command | What it does | Lesson |
git push -u origin NAME | Publish a new branch and set its upstream (docs). | 4 |
git push | Push the current branch to its upstream (after -u). | 4 |
git fetch | Download new commits and move origin/… pointers; never touches your files. | 4 |
git pull | git fetch then merge the upstream into the current branch. | 4 |
Pull requests with gh
| Command | What it does | Lesson |
gh repo create NAME --public --clone --add-readme | New GitHub repo with a first commit, cloned locally. | 2 |
gh pr create --fill | Open a PR from the current branch, title/body from commits. Add --draft, --base, --title, --body as needed (manual). | 4 |
gh pr view --web | Open the PR in your browser. | 4 |
gh pr checks --watch | Watch the PR's status checks until they finish. | 5 |
gh pr merge --squash --delete-branch | Squash merge and delete the branch locally and on GitHub. Alternatives: --merge, --rebase; --auto merges once requirements pass. | 4 |
Write Closes #12 in the PR body to close issue 12 on merge — only works when the PR targets the default branch (GitHub Docs).
Worktrees (parallel sessions)
| Command | What it does | Lesson |
git worktree add ../proj-a -b feature-a | New folder with a new branch checked out, sharing the same repository (docs). | 7 |
git worktree add ../proj-baseline -b baseline $(git merge-base main feature) | Worktree on a new branch at the merge base, for a baseline run of an eval. | 12 |
git worktree list | Main worktree first, then linked ones with their branches. | 7 |
git worktree remove ../proj-a | Remove a clean worktree (--force if it has changes). | 7 |
git worktree prune | Clean up records of worktrees whose folders are gone. | 7 |
claude -w NAME | Start Claude Code in .claude/worktrees/NAME/ on new branch worktree-NAME (docs). | 7 |
claude --worktree NAME --resume | Return to a kept worktree session. | 7 |
A branch can be checked out in only one worktree at a time.
Escape hatches
| Command | What it does | Lesson |
git stash (-u for untracked) | Shelve uncommitted changes to get a clean working tree (docs). | 2 |
git stash pop | Re-apply the latest stash and drop it from the list. | 2 |
git restore FILE | Discard uncommitted edits to FILE (docs). | 6 |
git restore --staged FILE | Unstage FILE, keeping the edits. | 6 |