Git Foundations / Final Challenge

Final challenge: fix and share a team change

Lesson 31 of 33. Open to read. No account needed.

The Situation

You are Asha, working on a café's menu with your teammate Ravi through a shared repository. Before you started work this morning:

  • You had pushed a branch, add-cake, that adds cake to the menu. It is not on main yet.
  • Ravi pushed two commits to main. One, "Add hot chocolate", is wanted. The other, "Update tea price", set tea to 20.00 by mistake; the owner confirms it should stay at 2.00.

Your job is to deliver the cake without losing anyone's work.

This challenge uses skills from across the course: inspecting history, reverting a shared commit, resolving merge conflicts, pulling and pushing, and cleaning up branches. Try it without looking back first; the hints and the explained solution are below.

Exercise: Deliver the Fixed Feature

Starting state: Git configured as in the configuration lesson.

  1. Run the setup. It creates the shared repository, your clone you and Ravi's clone teammate, and replays the morning so far. You end in your own clone:

    mkdir -p ~/git-practice/final-challenge
    cd ~/git-practice/final-challenge
    git init --bare -b main shared.git
    git clone shared.git you
    git clone shared.git teammate
    cd you
    git config user.name "Asha Rao"
    git config user.email "asha@example.com"
    cat > menu.md <<'EOF'
    # Menu
    
    Tea: 2.00
    Coffee: 2.50
    Juice: 3.00
    EOF
    git add menu.md
    git commit -m "Add menu"
    git push -u origin main
    git switch -c add-cake
    cat >> menu.md <<'EOF'
    Cake: 3.50
    EOF
    git commit -am "Add cake to the menu"
    git push -u origin add-cake
    git switch main
    cd ../teammate
    git config user.name "Ravi Kumar"
    git config user.email "ravi@example.com"
    git pull
    cat > menu.md <<'EOF'
    # Menu
    
    Tea: 20.00
    Coffee: 2.50
    Juice: 3.00
    EOF
    git commit -am "Update tea price"
    cat >> menu.md <<'EOF'
    Hot chocolate: 3.00
    EOF
    git commit -am "Add hot chocolate"
    git push
    cd ../you
    
  2. Complete the task. In your clone, you:

    • Undo the tea price change on the shared main, keeping the hot chocolate.
    • Bring add-cake up to date with main. Where the cake and the hot chocolate conflict, keep both, with hot chocolate first.
    • Put the cake on the shared main.
    • Delete add-cake locally and in the shared repository.
    • Never use --force or --force-with-lease: these branches are shared.
  3. Check your result with these acceptance checks, run in you:

    git log --oneline --graph
    git status
    cat menu.md
    git ls-remote --heads origin
    

    All of these must hold:

    • The log contains Revert "Update tea price" and the merge that brought main into add-cake, and the cake commit is on main.

    • git status says your branch is up to date with origin/main and the working tree is clean.

    • menu.md reads exactly:

      # Menu
      
      Tea: 2.00
      Coffee: 2.50
      Juice: 3.00
      Hot chocolate: 3.00
      Cake: 3.50
      
    • git ls-remote --heads origin lists only refs/heads/main.

    • The shared history still contains Ravi's original "Update tea price" and "Add hot chocolate" commits, which proves nothing was rewritten.

  4. Write down, in a sentence each, why you chose each step. The Check Your Understanding questions below ask for the same reasoning.

Hints, from gentle to specific. Read one at a time, only if you are stuck:

  • Hint 1: Your main is behind. Start by getting Ravi's commits, then look at what the bad commit changed.
  • Hint 2: The bad commit is shared, so it must stay in the history. Which undo command adds a commit instead of removing one?
  • Hint 3: add-cake is shared too. To bring main into it, merge rather than rebase. Expect a conflict at the end of menu.md.
  • Hint 4: Once add-cake contains main, merging it into main is a fast-forward. Then delete the branch with git branch -d and git push origin --delete.

If something differs:

What you seeLikely causeNext step
The revert reports a CONFLICTYou reverted the wrong commit, or main was not up to dategit revert --abort, git pull, then check the commit with git show
[rejected] when pushing mainThe shared main has commits you lackgit pull, then push again
menu.md has no hot chocolate after the mergeRavi's line was dropped while resolvingFix the file, then commit the correction
git branch -d add-cake says is not fully mergedThe cake is not on main yetMerge add-cake into main first
You want to start againAny reasonRemove ~/git-practice/final-challenge and rerun the setup
  1. Clean up when you have finished:

    cd ~/git-practice
    ls
    rm -rf final-challenge
    ls
    

Check Your Understanding

Explain your decisions:

  1. Why revert "Update tea price" instead of resetting main back past it?
  2. Why merge main into add-cake instead of rebasing add-cake onto main?
  3. Ravi pulls after you finish. Will he need to fix anything? Why or why not?

Answer and Reasoning

Solution

In your clone, you:

git switch main
git pull
git log --oneline
git show HEAD~1
git revert --no-edit HEAD~1
git push
git switch add-cake
git merge main
cat > menu.md <<'EOF'
# Menu

Tea: 2.00
Coffee: 2.50
Juice: 3.00
Hot chocolate: 3.00
Cake: 3.50
EOF
git diff --check
git add menu.md
git merge --continue
git push
git switch main
git merge add-cake
git push
git branch -d add-cake
git push origin --delete add-cake

Step by step:

  1. git pull fast-forwards main with Ravi's two commits. git log and git show HEAD~1 confirm that "Update tea price" changed Tea: 2.00 to Tea: 20.00.
  2. git revert --no-edit HEAD~1 adds Revert "Update tea price", setting tea back to 2.00 while keeping "Add hot chocolate". Pushing it fixes the shared main.
  3. Merging main into add-cake conflicts at the end of menu.md: one side adds hot chocolate, the other cake. The resolution keeps both. git merge --continue opens your editor with Merge branch 'main' into add-cake; save and close it. Pushing updates the shared add-cake.
  4. On main, git merge add-cake fast-forwards, because add-cake now contains everything on main. Pushing shares the cake, and the last two commands remove the finished branch everywhere.

Understanding check

  1. "Update tea price" is on the shared main, and Ravi has it. Resetting main past it would rewrite shared history: the push would be rejected, and forcing it would also have thrown away "Add hot chocolate" or left Ravi's clone disagreeing with the shared repository. A revert undoes the change with a new commit, so everyone's history still agrees.
  2. add-cake was already pushed. Rebasing would replace its commit with a new one, so pushing it would need a force. Merging adds to the branch, so a normal push works.
  3. No. Every change you shared added to the history he already has, so his git pull simply fast-forwards to the new main.

References

This challenge introduces no new commands. The sources for each command are listed in the lessons that teach it.

Study this course with an account

Course access adds revision notes, the Quick Reference, saved progress, bookmarks and your own notes.

INR 99 plus 18% GST. 90 days of online access. No auto-renewal.

See course access

This website is operated by VECTAMETRIC EDTECH (OPC) PRIVATE LIMITED, operating as Vectametric.

Corporate Identity Number (CIN): U85499KA2026OPC229822. GSTIN: 29AAMCV8281D1ZS. Registered office: RS NO/38/2A/1 BASTAND, ROAD MAHANTESH NAGAR, Ramdurg, Ramdurg, Belgaum- 591123, Karnataka.

Queries and grievances: Prajval Honnungar, Grievance Officer and Data Protection Contact.

Telephone: +91 94800 09310. Support: support@vectametric.com. Grievances: support@vectametric.com.

Copyright 2026 VECTAMETRIC EDTECH (OPC) PRIVATE LIMITED. All rights reserved.

Vectametric home · Roadmaps · Vecta IT Exams · Vecta Government Exams · Vecta Banking & Finance Exams · Vecta Entrance Exams · About us · Contact · Privacy Policy · Terms and Conditions · No-Refund Policy