Git without fear · Chapter 28 of 28

Friday, 6 pm

By the end of this chapter you can sort out a real evening of Git trouble on your own: look first, pick the right fix for each mess, and leave GitHub in a straight, honest line. Build it in your browser: a real editor and terminal, AI that explains, and tests that tell you when it works.

  • Part: Friday, 6 pm
  • 5 tasks
  • Git
  • In the all labs plan

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

Why you need this

Friday, 6 pm. Meera holds up her phone: forty orders in an hour, all for free chai. Bunty's "Make every chai free for Friday", meant as a joke for the team, went to GitHub's main, and Ravi has pushed his ginger chai on top of it since. Bunty also committed "Start the delivery page" on main (not pushed, it belongs on a branch), and your half-done delivery form is in the stash. Dev, the CTO: "Nobody goes home until main is right." Kabir and Bunty are watching you, not helping.

You have met every piece of this during the week, but never all at once, and here the order matters. Reset main before giving Bunty's commit a branch and you are back in the reflog. Pop the stash on main and you get a conflict. Reset the free chai away and force-push, and Ravi's ginger chai vanishes from everyone's GitHub.

What you build: 5 tasks

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

  1. Task 1

    The real prices back on GitHub's main

    Bunty made every chai FREE on GitHub's main. Put the real prices back.

    1. Undo the free-chai commit with git revert (task 2).

    2. The revert stops with a conflict in menu.txt, because of Ravi's ginger chai line.

    3. Write menu.txt as it should be: the real prices, Ravi's ginger chai line, the bun maska, and no conflict marker lines.

    4. Finish the revert and push main to GitHub.

    To pass: menu.txt on GitHub's main has the lines Masala chai 40, Cutting chai 25, Ginger chai 35 and Bun maska 50. It has no FREE and no conflict markers.

  2. Task 2 · interview question

    Interview: undo the free chai with a revert, never a force push

    Interview question: how do you undo a commit that is already on GitHub? Use git revert, never a force push.

    1. Find "Make every chai free for Friday" in the history. It is not the newest commit: Ravi's "Add ginger chai" is on top.

    2. Run git revert on that commit. Keep Git's own commit message.

    3. Push main with a plain git push.

    To pass: GitHub's main still has "Make every chai free for Friday" and "Add ginger chai", and a commit whose message starts with Revert "Make every chai free for Friday". No push you typed in the chapter folder used --force, -f or a + before the branch name. A push that failed also counts.

  3. Task 3

    Bunty's delivery commit off main, onto delivery

    Bunty made "Start the delivery page" on main. It belongs on its own branch.

    1. Make a branch called delivery while main still points at that commit.

    2. Move main back to where GitHub's main is, with its files too. Your form is safe in the stash.

    3. Do this before the revert, so main does not lose your revert.

    To pass: your main has no "Start the delivery page" commit and is the same commit as GitHub's main. The branch delivery has "Start the delivery page".

  4. Task 4

    Your stashed form committed on delivery

    Your half-done address form is in the stash. Commit it on delivery.

    1. Switch to the branch delivery. Do not bring the stash back on main.

    2. Bring the stash back and remove it from the stash list (pop does both).

    3. Commit delivery.html on delivery.

    To pass: delivery.html committed on delivery has your address form, the line with input name="address". git stash list shows nothing.

  5. Task 5 · interview question

    Interview: delivery on top of the fixed main, with no merge commit

    Interview question: how do you put a branch on top of a new main, with no merge commit? Use a rebase.

    1. After the revert is on main, switch to delivery and rebase it onto main. Do not merge.

    2. Commit your form on delivery (task 4).

    3. Push delivery to GitHub for the first time, and set its upstream. Do not push it before the rebase: it would then need a force push, and task 2 would fail.

    To pass: on GitHub, delivery has all of GitHub's main in its history, with no merge commit. "Start the delivery page" is in it exactly once, and its delivery.html has your address form.

What you will learn

  • Look before you touch: status, the stash list and the graph tell you what is wrong.
  • The right undo for each commit: a branch and a reset for the unpushed one, a revert for the pushed one.
  • A conflict in a revert, finished the same way as in a merge.
  • Rebase, stash pop and push to ship the delivery work in a straight line.

More in Friday, 6 pm

Build "Friday, 6 pm" yourself

Your first week on Tapri’s team, and every Git situation it throws at you. 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 without fear are free. This one comes with the all labs plan.