Locked learning resources

Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Locked learning resources

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Merge Parallel Branches One at a Time

At the end of the last lesson, you had two branches, each with one reviewed commit: issue-1-search, where search ignores capitalization, and issue-3-found-where, where each search result says where the item was found. Both start from the same commit on main, and neither change is on main yet.

Each branch passed the tests in its own folder, where you ran them yourself, but nobody has run them with both changes in one place. Separate files can still affect each other when the app runs, so you merge one branch at a time, rerun the tests after each merge, and check the page once both are in.

Key Points

  • Merging brings a branch’s commits into the branch you’re on. So you work in the lost-property folder, on the main branch. Run git switch main first to be sure.
  • A fast-forward moves main forward. When main has no new commits since the branch started, Git moves main to the branch’s commit.
  • A merge commit joins two lines. Once main has a commit the branch doesn’t have, Git makes a merge commit instead. The --no-edit option keeps Git’s suggested message rather than opening your editor for one. If an editor does open for the message, save and close it to keep Git’s message.
  • Rerun npm test after each merge. After the second merge, the tests run with both changes together for the first time. Your commit IDs and test count will differ from the video’s. Check for fail 0.
  • Check the page once on main. The tests cover search, but not how the results page shows an item. Start the server on main and search for “Fiddle” with a capital F. The capital F working is issue #1’s fix, and the location in each result is issue #3’s.
  • Remove the worktrees once their branches are merged. Stop the server with Ctrl+C and exit each folder’s agent session first. The commits are already on main, so git worktree remove deletes only the folder, and the branches stay. git worktree list then shows one folder, on main.
  • If git worktree remove refuses, read what’s left. It refuses if the folder still has changes you haven’t committed. If it does, run git status in that folder and read what it lists. Discard leftovers before you try again. Anything worth keeping there isn’t on main yet. Use --force only when you’re sure nothing there is needed.
  • The review queue sets the pace. Two agents worked at the same time, but each merge waited for your review and your test run.

The Commands From the Video

Locked learning resources

Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Locked learning resources

The full lesson is for members only. Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

00:00 At the end of the last lesson, you had two branches, each with one reviewed commit. One fixes issue one, so search ignores capitalization. The other, for issue three, shows where each item was found.

00:14 Here’s the repository’s history. Both branches start from the same commit on main. Main hasn’t moved, so neither fix is on it yet. Each branch passed the tests in its own folder, where you ran them yourself.

00:28 However, nobody has run them with both changes in one place, and that’s what main will hold. Separate files can still affect each other when the app runs.

00:38 Say issue one’s fix stopped sending each item’s location. Issue three’s results would then end in found at undefined. So you’ll merge one branch at a time, rerun the tests after each merge, and check the page once both are in.

00:56 Merging brings a branch’s commits into the branch you’re on. So you work in the lost-property folder, on the main branch. Switch to main first to be sure. Here, Git says you’re already there.

01:08 Now merge it. Main has no new commits since the branch started, so Git moves main forward to the branch’s commit. That’s a fast-forward.

01:19 Then run the tests on main. All four pass, including the new capitalization test.

01:26 Main has moved. It now holds issue one’s commit, and issue three’s branch doesn’t. Your turn: pause the video and predict. Can Git fast-forward main this time?

01:45 No. Main has a commit the branch doesn’t have, so Git makes a merge commit that joins the two lines. The --no-edit option keeps Git’s suggested message, rather than opening your editor for one.

02:00 Run the tests again. This is the first run with both changes together, and all four still pass.

02:08 The tests cover search, but not how the results page shows an item. So check the page too, once, on main. Start the server in the main folder, and search for Fiddle with a capital F.

02:23 Two results come back, and each says where it was found. The capital F working is issue one’s fix. The location is issue three’s.

02:35 Stop the server with Control-C. Both branches are merged, so their worktree folders can go. Exit each folder’s agent session first. The commits are already on main, so git worktree remove deletes only the folder, and the branches stay.

02:52 It refuses if the folder still has changes you haven’t committed. git worktree list now shows one folder, on main. Two jobs had to wait for both merges, the day’s changelog entry and the project map.

03:08 Both sessions stayed out of those files. Now you run each once, on main, and the text below this video walks you through it. The rule, then, is to merge one branch, run the tests, and then merge the next.

03:23 If a test fails, you know which merge brought it in, even when the cause is how two changes combine. That’s where you look first. Stop there, and get the tests passing again before the next merge.

03:37 Two agents worked at the same time. But each merge waited for your review and your test run. However many agents work at once, the review queue sets the pace.

03:49 Next, in Exercise: Plan a Parallel Afternoon, you’ll decide which of the festival’s tasks can run side by side.

Become a Member to join the conversation.