Git disasters · Chapter 10 of 14

A bad merge on main

Build it in your browser: a real editor and terminal, AI that explains, and tests that tell you when it works.

  • Part: Merges and detective work
  • 3 tasks
  • Git
  • In the all labs plan

The first 2 chapters of Git disasters are free. This one comes with the all labs plan.

What you build: 3 tasks

Each task has tests. You write the code in the lab's editor and press Check.

  1. Task 1

    See what happened: find the merge that broke main

    Since Bunty's merge, the tests on main fail and checkout is broken. Find the merge commit that brought the half-finished new-checkout branch into main.

    1. Run node --test on main. See which test fails.

    2. Show the history as a graph. Find where new-checkout joins main.

    3. Write the hash of that merge commit into answer.txt, in the case's folder.

    To pass: answer.txt has the hash of that merge commit (7 characters or more), and no other hash.

  2. Task 2

    Fix: undo the merge on GitHub without rewriting main

    Undo the merge on GitHub. Ravi already pushed a commit on top, so do not change main's old commits. Undo the merge with a new commit.

    1. Make a new commit that undoes the merge. Keep main's own side of the merge.

    2. Run node --test. All tests must pass.

    3. Push main to GitHub. Use a normal push, not a force push.

    To pass: GitHub's main still has every commit it had, Ravi's "Add the Jayanagar outlet" too. Its files are the same as on main just before the merge, plus Ravi's Jayanagar line in outlets.txt, and nothing else. node --test passes on GitHub's main.

  3. Task 3

    Guard it: no merge commit with failing tests

    Stop the next merge that breaks the tests.

    1. Write a hook script in .git/hooks/pre-merge-commit.

    2. It runs node --test. When the tests fail, it stops the merge.

    3. When the tests pass, it lets the merge through.

    4. Make the file executable.

    To pass: do task 2 first, so the tests on your main pass. The Check then tries your hook in a copy of your repository, on main. It merges (with --no-ff) a branch that adds a failing test. Main must not move. Then it merges a branch that adds a passing test. That must make a merge commit.

What you will learn

  • See what happened: find the merge that broke main
  • Fix: undo the merge on GitHub without rewriting main
  • Guard it: no merge commit with failing tests

More in Merges and detective work

Build "A bad merge on main" yourself

Bunty is Tapri's new junior developer, and Kabir keeps handing you the Git incidents left behind. Each is a disaster interviews love to ask about. A real editor and terminal in your browser, AI that explains, and a Check that says when it works.

The first 2 chapters of Git disasters are free. This one comes with the all labs plan.