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
| Step | Command | What it does |
| 0. Start fresh | git switch main · git pull | Branch from an up-to-date main |
| 1. Branch | git switch -c <name> | Create a label at the current commit and move HEAD to it |
| 2. Commit | git 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 push | Send new commits to the linked remote branch |
| 3. Open PR | gh pr create --fill | Title and body come from your commits (--draft for early feedback) |
| 3. Inspect PR | gh pr view --web | Open the PR in the browser; read Files changed |
| 4. Address review | commit · git push | The PR updates itself |
| 5–6. Merge & clean up | gh pr merge --merge --delete-branch | Merge on GitHub, delete the branch locally and remotely |
| 7. Sync | git switch main · git pull | Bring the merge down to local main |
Look around
| Command | Answers |
git status | What branch am I on, and what’s changed? |
git branch | Which local branches exist? (* = HEAD) |
git branch -a | …including remote-tracking branches |
git log --oneline --graph --all | Where does every label point? |
| Command | Answers |
gh pr list | Which PRs are open? |
gh pr status | What’s the state of my PRs? |
gh pr diff | Show this PR’s diff in the terminal |
gh pr checks | Have 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)
| Command | Network | Moves |
git fetch | download | origin/* only. Files and local branches are untouched |
git fetch --prune | download | …and deletes bookmarks for branches gone from GitHub |
git pull | download | fetch, then integrate origin/<branch> into the current branch (fast-forward only by default) |
git pull --no-rebase | download | fetch, then merge even if both sides have new commits (creates a merge commit) |
git push | upload | GitHub’s branch and your origin/<branch>. Rejected if GitHub has commits you lack |
git status says | Meaning | Do |
| up to date with ‘origin/main’ | matches your last-known GitHub | git fetch if unsure |
| ahead by N | N commits only on your laptop | git push |
| behind by N, can be fast-forwarded | bookmark has N commits you lack | git pull |
| have diverged | both sides have new commits | git pull --no-rebase, then push (or rebase: Lesson 6) |
! [rejected] (fetch first) on push | GitHub has commits you lack | pull, 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
| Step | Command |
| Update branch from main | git fetch · git merge origin/main |
| What’s conflicted? | git status (look for “both modified”) |
| Back out, nothing lost | git merge --abort |
| Resolve | edit to the intended result, delete all 3 marker lines |
| No markers left? | grep -nE '^(<{7}|={7}|>{7})' <file> |
| Mark resolved · finish | git 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
| Step | Command / place |
| Read claims | gh pr view <n> |
| Check scope | gh pr diff <n> --name-only |
| Read every line | gh pr diff <n> · Files changed tab |
| Run it | gh pr checkout <n> … git switch main |
| Line comment | hover line → + → Start a review (pending, only you see it) |
| Suggest a fix | ± icon → edit the suggestion block |
| Submit | Review changes → Comment / Approve / Request changes |
| From terminal | gh pr review <n> -c|-a|-r -b "…" |
| Look for | Ask |
| Functionality | Does the code do what the task and the description claim? |
| Scope | Does every changed file belong to this task? |
| Tests | Would they fail if the code broke? Were any deleted? |
| Every line | Debug 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
| Task | Command / place |
| Add a check | YAML in .github/workflows/; one job = one check |
| Watch checks | gh pr checks --watch |
| Why it failed | gh run view --log-failed |
| Create ruleset | Settings → Rules → Rulesets → New branch ruleset |
| See rules on a branch | gh ruleset check main |
| Rejected push to main | git switch -c topic → git branch -f main origin/main |
Solo ruleset on main | Setting |
| Restrict deletions | on (default) |
| Block force pushes | on (default) |
| Require a PR | on, 0 approvals |
| Require status checks | the job id, e.g. test |
| Bypass list | empty (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
| Method | gh pr merge flag | History result |
| Merge commit | --merge | All branch commits kept, plus a merge commit marking the join (always: GitHub merges with --no-ff) |
| Squash and merge | --squash | The PR becomes one commit on main; individual commits are lost |
| Rebase and merge | --rebase | Commits 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)