Reference · Git workflow in the age of agents

GitHub flow cheat sheet

The commands for one trip around the loop. Grows with each lesson: Lesson 1 · Lesson 2 · Lesson 3 · Lesson 4. Terms: glossary.

Model: a branch is a movable pointer to a commit. HEAD points to the branch you’re on. A commit moves only the branch HEAD points to. (Pro Git §3.1)

The loop

StepCommandWhat it does
0. Start freshgit switch main · git pullBranch from an up-to-date main
1. Branchgit switch -c <name>Create a label at the current commit and move HEAD to it
2. Commitgit add <files> · git commit -m "…"One self-contained change per commit
2. Push (first time)git push -u origin <name>Publish the branch and link it to origin/<name>
2. Push (later)git pushSend new commits to the linked remote branch
3. Open PRgh pr create --fillTitle and body come from your commits (--draft for early feedback)
3. Inspect PRgh pr view --webOpen the PR in the browser; read Files changed
4. Address reviewcommit · git pushThe PR updates itself
5–6. Merge & clean upgh pr merge --merge --delete-branchMerge on GitHub, delete the branch locally and remotely
7. Syncgit switch main · git pullBring the merge down to local main

Look around

CommandAnswers
git statusWhat branch am I on, and what’s changed?
git branchWhich local branches exist? (* = HEAD)
git branch -a…including remote-tracking branches
git log --oneline --graph --allWhere does every label point?
CommandAnswers
gh pr listWhich PRs are open?
gh pr statusWhat’s the state of my PRs?
gh pr diffShow this PR’s diff in the terminal
gh pr checksHave the CI checks passed?

Sync with GitHub

Model: there are three mains: GitHub’s, your bookmark origin/main, and your local main. git status compares the last two and never contacts GitHub. (Pro Git §3.5; Lesson 2)

CommandNetworkMoves
git fetchdownloadorigin/* only. Files and local branches are untouched
git fetch --prunedownload…and deletes bookmarks for branches gone from GitHub
git pulldownloadfetch, then integrate origin/<branch> into the current branch (fast-forward only by default)
git pull --no-rebasedownloadfetch, then merge even if both sides have new commits (creates a merge commit)
git pushuploadGitHub’s branch and your origin/<branch>. Rejected if GitHub has commits you lack
git status saysMeaningDo
up to date with ‘origin/main’matches your last-known GitHubgit fetch if unsure
ahead by NN commits only on your laptopgit push
behind by N, can be fast-forwardedbookmark has N commits you lackgit pull
have divergedboth sides have new commitsgit pull --no-rebase, then push (or rebase: Lesson 6)
! [rejected] (fetch first) on pushGitHub has commits you lackpull, then push again

Sources: git-fetch, git-pull.

Merge conflicts

<<<<<<< HEAD
your side (branch you're on)
=======
their side (branch you merged in)
>>>>>>> origin/main
StepCommand
Update branch from maingit fetch · git merge origin/main
What’s conflicted?git status (look for “both modified”)
Back out, nothing lostgit merge --abort
Resolveedit to the intended result, delete all 3 marker lines
No markers left?grep -nE '^(<{7}|={7}|>{7})' <file>
Mark resolved · finishgit add <file> · git commit --no-edit
Is the PR mergeable?gh pr view --json mergeable

Resolving isn’t picking a winner: check that both sides’ intent survived. Sources: Pro Git §3.2, git-merge. Lesson 3.

Reviewing a PR

StepCommand / place
Read claimsgh pr view <n>
Check scopegh pr diff <n> --name-only
Read every linegh pr diff <n> · Files changed tab
Run itgh pr checkout <n> … git switch main
Line commenthover line → + → Start a review (pending, only you see it)
Suggest a fix± icon → edit the suggestion block
SubmitReview changes → Comment / Approve / Request changes
From terminalgh pr review <n> -c|-a|-r -b "…"
Look forAsk
FunctionalityDoes the code do what the task and the description claim?
ScopeDoes every changed file belong to this task?
TestsWould they fail if the code broke? Were any deleted?
Every lineDebug output, unused imports, swallowed errors?

Authors can’t approve their own PRs, including agent PRs opened with your login. Sources: GitHub Docs, Google eng-practices. Lesson 4.

Checks and rulesets

TaskCommand / place
Add a checkYAML in .github/workflows/; one job = one check
Watch checksgh pr checks --watch
Why it failedgh run view --log-failed
Create rulesetSettings → Rules → Rulesets → New branch ruleset
See rules on a branchgh ruleset check main
Rejected push to maingit switch -c topic → git branch -f main origin/main
Solo ruleset on mainSetting
Restrict deletionson (default)
Block force pusheson (default)
Require a PRon, 0 approvals
Require status checksthe job id, e.g. test
Bypass listempty (you = your agents)

A green check proves only what the tests test, and the PR supplies both the tests and the workflow. Review changes to .github/workflows/ and the tests. Free plan: rulesets work on public repos only. Sources: GitHub Docs, rulesets, Actions quickstart. Lesson 5.

Merge methods on GitHub

Methodgh pr merge flagHistory result
Merge commit--mergeAll branch commits kept, plus a merge commit marking the join (always: GitHub merges with --no-ff)
Squash and merge--squashThe PR becomes one commit on main; individual commits are lost
Rebase and merge--rebaseCommits replayed onto main as new commits (new SHAs), with no merge commit

Source: GitHub Docs, “About merge methods on GitHub”. Flags: gh manual.

Agent rule of thumb

One task means one branch, and main moves only through a reviewed PR. That applies to agents too. (GitHub flow; Claude Code worktrees)

Related ideas