Capstone: Kusina, for real · lesson 3 of 6
Commands and ideas in this lesson
Agit switch -c3.2: a branch for each change
Bgit push -u origin5.2: share the branch
Cgit merge origin/main4.7: bring main into your branch
DConflict markers3.4: resolve, add, commit
EPull request review5.2: read, comment, approve

Two cooks

Last updated

Now both cousins work at once. Ana and Carla each take a branch, change things, push, and ask the other to review. Three of their changes are set up to collide, the way real ones do: the same line, the same spot in the README, and the same new file. You'll play both sides, and resolve all three.

By the end of this lesson you can

  • Work on branches in two clones at once, and keep each up to date with main
  • Open, review and merge pull requests (or review and merge by hand without a host)
  • Resolve three kinds of conflict: one line, one spot, one new file on both sides

The plan

Who changes what
Ana, on branch more-vinegarCarla, on branch carla-additions
adobo.md, the vinegar line- 1/2 cup cane vinegar- 1/3 cup cane vinegar, or less if it’s strong
README.md, a new last lineAsk Ana about the adobo.Ask Carla about anything with coconut.
sisig.md, a new fileHer version: pork, onions, calamansiHer version: pork, chicken liver, chili

Each row will conflict. Ana's branch is reviewed and merged first, so Carla is the one who meets the conflicts, and resolves them on her branch before hers can merge. That's the usual way: whoever merges second updates their branch.

Keep two terminals open, one in ~/ana-kusina and one in ~/carla-kusina, and check which you're in before each command.

Ana: more vinegar

In ~/ana-kusina, make a branch and three changes, one commit each:

Terminal
git switch -c more-vinegar
(edit adobo.md: the vinegar line becomes - 1/2 cup cane vinegar)
git commit -am "Use more cane vinegar in the adobo"
(add a last line to README.md: Ask Ana about the adobo.)
git commit -am "Say who to ask about the adobo"
(make sisig.md with Ana’s recipe)
git add sisig.md
git commit -m "Add Ana’s sisig recipe"
git push -u origin more-vinegar

Then, on a hosting site, open a pull request from more-vinegar into main, with a description that says what and why (lesson 5.2).

Carla: less vinegar, and sisig

At the same time, in ~/carla-kusina (she hasn't seen Ana's branch):

Terminal
git switch -c carla-additions
(edit adobo.md: the vinegar line becomes - 1/3 cup cane vinegar, or less if it’s strong)
git commit -am "Warn that strong vinegar needs less"
(add a last line to README.md: Ask Carla about anything with coconut.)
git commit -am "Say who to ask about coconut dishes"
(make sisig.md with Carla’s recipe)
git add sisig.md
git commit -m "Add Carla’s sisig recipe"
git push -u origin carla-additions

And open a second pull request, from carla-additions into main.

Review and merge Ana’s

As Carla, review Ana's pull request on the host: read the diff, leave at least one comment on a line, then approve. As Ana, reply to the comment, then merge.

Afterwards, in ~/ana-kusina: git switch main, git pull, and delete the merged branch with git branch -d more-vinegar.

Carla catches up: three conflicts

Carla's pull request now says it can't be merged automatically. She brings the new main into her branch and resolves it there:

Terminal
git fetch
git merge origin/main
Auto-merging README.md
CONFLICT (content): Merge conflict in README.md
Auto-merging adobo.md
CONFLICT (content): Merge conflict in adobo.md
Auto-merging sisig.md
CONFLICT (add/add): Merge conflict in sisig.md
Automatic merge failed; fix conflicts and then commit the result.

Three kinds, one method: open each file, find the markers (lesson 3.4), decide what the file should say, delete the markers, and git add it.

  1. adobo.md, one line. Neither side is simply right. Talk (or, playing both, decide): perhaps - 1/2 cup cane vinegar, or 1/3 cup if it’s strong.
  2. README.md, one spot. Both lines belong. Keep both, one after the other.
  3. sisig.md, a whole file on each side. An add/add conflict marks the differences throughout. Merge the two recipes into one, or keep Ana's and save Carla's as sisig-with-liver.md.

Then check nothing is left and finish:

Terminal
git diff --check
git status
git commit
git push

git diff --check prints any conflict markers still in staged or unstaged changes; no output is good. git commit with no message opens the editor with a ready-made "Merge remote-tracking branch…" message.

Review and merge Carla’s

As Ana, review Carla's pull request: check especially how the conflicts were resolved, by reading the merge commit's changes. Approve, then merge (or, without a host, merge carla-additions into main with --no-ff and push). Both clones then git switch main and git pull.

Check your history

In either clone:

Terminal
git log --graph --oneline -8
*   e41c2b7 (HEAD -> main, origin/main) Merge pull request #2 from ana/carla-additions
|\
| *   9d8a3f0 Merge remote-tracking branch 'origin/main' into carla-additions
| |\
| |/
|/|
* |   6b2e1d4 Merge pull request #1 from ana/more-vinegar
...

You should see two merge commits on main, and a merge inside Carla's branch where she resolved the conflicts. grep -c "<<<<<<<" *.md should print 0 for every file.

Ana’s branch merged first. Whose job is it to resolve the conflicts with Carla’s?
Both cousins added a new file called sisig.md. What kind of conflict is that?

Sources

Every command on this page behaves as these pages describe, and the sandbox prints what Git 2.55 prints. Hosting features (pull requests, protected branches) come from the host’s own documentation.

All sources for Simple Git