Lesson 2 · Git workflow in the age of agents
Your laptop has a bookmark, not a live view
Three copies of main, and which command moves which. About 25 minutes.
Today’s win: before you run fetch, pull, or push, you’ll be able to say what it will move, and you’ll catch git status telling you something out of date.
Three mains, not one
In Lesson 1 you saw origin/main in your log and moved on. Here’s what it is. There are really three things called “main”:
mainon GitHub: the real shared branch. It moves whenever anyone pushes or merges a PR, including an agent.origin/mainon your laptop: a remote-tracking branch. It’s Git’s note of where GitHub’smainwas the last time you checked.mainon your laptop: your own branch. It moves when you commit, pull, or merge.
“Think of them as bookmarks, to remind you where the branches in your remote repositories were the last time you connected to them.” Quote and the next one: Pro Git §3.5, “Remote Branches”. The book also says these are “local references that you can’t move; Git moves them for you whenever you do any network communication.”
The key detail is that a bookmark doesn’t update itself: “as long as you stay out of contact with your origin server, your origin/master pointer doesn’t move.” (master is the book’s older name for main.)
“git status tells me whether I’m up to date with GitHub.” It doesn’t. It compares your main with your bookmark origin/main, and it never contacts GitHub. So “Your branch is up to date with ‘origin/main’” can be true while GitHub has ten new commits.
Which command moves which
| Command | Talks to GitHub? | Moves |
|---|---|---|
git commit | No | your main (the branch HEAD is on) |
git fetch | Yes, downloads | origin/main only. Your files and your main are untouched. |
git pull | Yes, downloads | git fetch, then brings origin/main into your main |
git push | Yes, uploads | GitHub’s main, and your origin/main with it |
fetch “will not modify your working directory at all” (Pro Git §3.5). pull “runs git fetch … Then it integrates that branch into the current branch” (git-pull docs).
So pull isn’t a separate kind of download. It’s a fetch with an integration step added.
Play with it first
Click the buttons and watch which box changes. Newly arrived commits glow. Violet commits are your teammate’s and blue ones are yours. Before each click, predict which box will change and what the terminal will say.
Stuck on challenge 3?
A rejected push means GitHub has commits that your main doesn’t contain. You have to bring them in first. Plain git pull refuses when both sides have new commits. On git 2.39 that’s the “Need to specify how to reconcile divergent branches” error. git pull --no-rebase tells it to merge, which creates a merge commit (the square M) that contains both sides. Then the push goes through. Lessons 3 and 6 cover what happens when both sides change the same lines, and the rebase alternative.
Default behaviour: “git pull --ff-only … fails if your local branch has diverged from the remote branch. This is the default.” git-pull docs.
Agents make this matter more. A cloud agent or a teammate’s Claude Code session can push branches and merge PRs while you aren’t looking, and your laptop learns about it only when you fetch. Before you review an agent’s branch locally, or start new work from main, sync first. The habit is git switch main, then git pull.
Do it for real
Back to ~/Work/git-sandbox. To play the teammate, you’ll make a second clone of the same GitHub repo. It stands in for a colleague’s laptop, or an agent working somewhere else.
-
Find the stale bookmark left over from Lesson 1
cd ~/Work/git-sandbox git branch -aYou should still see
remotes/origin/add-greeting, even though that branch was deleted on GitHub. Predict why before reading on. A bookmark changes only when you talk to the server, and a plain fetch doesn’t remove bookmarks for deleted branches. Clean it up:git fetch --prune git branch -a--prune: “Before fetching, remove any remote-tracking references that no longer exist on the remote.” git-fetch docs. Optional:git config --global fetch.prune truemakes every fetch do this. -
Become the teammate: clone, then run the whole PR loop from memory
cd ~/Work gh repo clone git-sandbox git-sandbox-teammate cd git-sandbox-teammateNow, without opening Lesson 1, take one change through the full loop. Make a branch, add a file
teammate.txt, commit, push, open a PR, and merge it with branch deletion. Recalling the commands is part of the practice.Check your commands (only after trying)
git switch -c add-teammate-note echo "Hi from your teammate" > teammate.txt git add teammate.txt git commit -m "Add teammate note" git push -u origin add-teammate-note gh pr create --fill gh pr merge --merge --delete-branch -
Go back to your clone and ask git status
cd ~/Work/git-sandbox git statusGitHub’s
mainjust moved. Predict whatgit statussays, then run it. It says “up to date with ‘origin/main’”, because your bookmark hasn’t moved andstatusdidn’t ask GitHub. -
Fetch, and watch the bookmark move
git fetch git status git log --oneline --graph --allPredict the number before you run it: behind by how many commits? It’s 2: the teammate’s commit and the merge commit GitHub created. In the log,
origin/mainis now above(HEAD -> main). Runlsand notice thatteammate.txtisn’t there yet. Fetch doesn’t touch your files. -
Pull, and catch up
git pull git log --oneline --graph --all lsThe output says
Fast-forward. Yourmainhad no new commits of its own, so Git only slid the label forward to whereorigin/mainis. Nothing needed merging. Nowteammate.txtis there. -
Be “ahead”: commit on a branch before pushing
git switch -c add-notes echo "Remotes are bookmarks" > notes.txt git add notes.txt && git commit -m "Add notes" git push -u origin add-notes echo "fetch moves origin/*, pull also merges" >> notes.txt git commit -am "Expand notes" git statusThe status reads “ahead of ‘origin/add-notes’ by 1 commit”: your second commit exists only on your laptop.
git pushsends it and moves both GitHub’s branch and your bookmark. Rungit statusagain to see “up to date”. -
Finish the loop
git push gh pr create --fill gh pr merge --merge --delete-branch git switch main git pull git fetch --prune git log --oneline --graph --all
Close the feedback loop: paste the final git log --oneline --graph --all into Claude Code. You should see two more merge commits than last time, with HEAD -> main and origin/main on the same commit. I’ll walk through anything that looks off.
Recall it
No scrolling up. Try this again in two or three days, and also retry the Lesson 1 quiz. Spaced retrieval builds long-term memory.
Go deeper
Primary source: Pro Git §3.5, “Remote Branches”. Read up to “Tracking Branches”. Its diagrams show the same three-box idea with master.
Optional extra practice: the Remote tab on Learn Git Branching, levels “Push & Pull” 1–4.
Reference: GitHub flow cheat sheet (now with a sync section) · Glossary.
Did something print output you didn’t expect, or are you wondering why pull doesn’t just always merge? Ask me in Claude Code. Questions like these are what I’m here for.