Lesson 3 · Git workflow in the age of agents
A conflict is a question, not an error
Git asks for help when two people changed the same lines. Here you learn to read the markers, answer the question, and back out if you need to. About 30 minutes.
Today’s win: you’ll make a real conflict between two PRs, back out of it on purpose, then resolve it and merge. After that, conflicts should feel routine rather than alarming.
When Git stops and asks
Most merges are automatic. Git combines changes to different files, or to different parts of the same file, by itself. It stops only in one situation: Quote: Pro Git §3.2, “Basic Merge Conflicts”. GitHub adds the other common case: one side edits a file that the other side deleted (GitHub Docs, “About merge conflicts”).
“If you changed the same part of the same file differently in the two branches you’re merging, Git won’t be able to merge them cleanly.”
Nothing is broken when this happens. Git can’t know which change you wanted, so it puts both versions into the file, marks them, and waits for you to choose.
Reading the markers
Say you’re on my-greeting and you run git merge origin/main. The conflicted file looks like this:
<<<<<<< HEAD
Hello from me
=======
Hello from the teammate
>>>>>>> origin/main
- Top, between
<<<<<<< HEADand=======: your side, from the branch HEAD is on (my-greeting). - Bottom, between
=======and>>>>>>>: their side, from whatever you named in the merge command (origin/main).
“The part before the ======= is typically your side, and the part afterwards is typically their side.” git-merge docs, “How conflicts are presented”.
To resolve, edit that region into the version you actually want. You might keep one side, keep both, or combine them. Then delete all three marker lines and tell Git the file is done with git add.
“Resolving means picking a winner.” Often it doesn’t. If both sides made a real change, keeping only one quietly throws the other away. Git can’t notice that, so it falls to you. Drill 3 below shows the trap.
Your three moves, in order
| Moment | Command | What it does |
|---|---|---|
| See what’s conflicted | git status | Lists files under “Unmerged paths” as both modified |
| Back out completely | git merge --abort | Puts everything back the way it was before the merge started |
| Finish | edit · git add <file> · git commit --no-edit | Marks the file resolved, then creates the merge commit |
--abort: “try to reconstruct the pre-merge state.” The docs advise committing your work before any merge so the abort has nothing to lose. Finishing: “Edit the files into shape and git add them … Use git commit … to seal the deal.” git-merge docs.
git merge --abort is your escape route. If you’re confused partway through, abort, think it over, and merge again. Nothing is lost.
Drills: resolve in the browser
Each box is a conflicted file. Read the intent, edit the text, and press Check. Remove the marker lines yourself, because that’s what you’ll do in your editor.
Parallel agents are the most common source of conflicts. If two agents work on overlapping files at the same time, the second PR to merge will conflict. Two habits help. First, give agents tasks that touch separate areas of the code. Second, when a conflict does happen, merge one PR, then bring main into the other branch and resolve it there, just as you’ll do below. An agent can resolve the conflict for you, and GitHub can offer Copilot in the merge box, but you still check the merge result the way you did in Drill 3. Did both changes survive?
GitHub: “Simple line conflicts can often be resolved on GitHub … More complex conflicts must be resolved in a local clone and pushed back to the pull request branch.” About merge conflicts. Parallel agents get their own lesson (worktrees).
Do it for real
You’ll use both clones. The teammate changes greeting.txt and merges first. You change the same line on your own branch, so your PR conflicts.
-
Teammate: sync, and check your prediction
cd ~/Work/git-sandbox-teammate git status # you predicted: up to date git fetch git status # you predicted: behind (by 3) git pullYou’re already on
mainhere: last time,gh pr merge --delete-branchswitched you back after deleting the branch you were on.git pullshould report aFast-forward. -
Teammate: change the greeting and merge it (loop from memory)
Branch
teammate-greeting, replace the whole ofgreeting.txtwithHello from the teammate, commit, push, open a PR, and merge it with branch deletion.Check your commands (only after trying)
git switch -c teammate-greeting echo "Hello from the teammate" > greeting.txt git commit -am "Teammate greeting" git push -u origin teammate-greeting gh pr create --fill gh pr merge --merge --delete-branch -
You: change the same line, without syncing first
cd ~/Work/git-sandbox git switch -c my-greeting echo "Hello from me" > greeting.txt git commit -am "My greeting" git push -u origin my-greeting gh pr create --fill gh pr view --webOn GitHub the PR says the branch has conflicts that must be resolved, and the merge button is disabled. “You must resolve all merge conflicts before you can merge a pull request.” From the terminal,
gh pr view --json mergeableprintsCONFLICTING. If it saysUNKNOWN, GitHub is still checking, so try again after a few seconds. Quote: GitHub Docs, “About merge conflicts”. -
Bring main into your branch, and hit the conflict
git fetch git merge origin/main git statusPredict before running: which side will be on top in
greeting.txt? You should seeCONFLICT (content): Merge conflict in greeting.txt, andstatuslists it asboth modified. This uses your Lesson 2 model directly.fetchupdates theorigin/mainbookmark, andmergebrings it into the branch you’re on. -
Practise the escape route
git merge --abort git status cat greeting.txtThe status is clean and the file says
Hello from meagain, as if the merge never started. That’s why there’s no need to panic: you can always back out. -
Merge again and resolve it properly
git merge origin/main nvim greeting.txt # or any editorThe intent is that the team agreed the greeting should mention both of you. Make the file one line,
Hello from me and the teammate, and delete all three marker lines. Then check that no markers are left and finish the merge:grep -nE '^(<<<<<<<|=======|>>>>>>>)' greeting.txt # no output = clean git add greeting.txt git status # "All conflicts fixed but you are still merging." git commit --no-edit git log --oneline --graph --all--no-editkeeps Git’s default “Merge remote-tracking branch ‘origin/main’ into my-greeting” message, so nvim doesn’t open. -
Push, merge the PR, sync
git push gh pr view --json mergeable # now MERGEABLE gh pr merge --merge --delete-branch git switch main git pull git fetch --prune cat greeting.txt git log --oneline --graph --all
Close the feedback loop: paste the final git log --oneline --graph --all into Claude Code. This graph has a new shape, with one merge commit inside your PR and another that merges the PR itself. We’ll read it together.
Recall it
No scrolling up.
Spaced review: try the Lesson 2 quiz again before this one. Its ideas (fetch, origin/main) are what step 4 relied on.
Go deeper
Primary source: Pro Git §3.2, from “Basic Merge Conflicts” to the end (about 5 minutes). Then GitHub’s Resolving a merge conflict using the command line covers the same steps, including the edit-versus-delete case.
Reference: Cheat sheet (now with a conflicts section) · Glossary.
Want to know why there are two merge commits, or what happens if both sides delete lines? Ask me in Claude Code.