Curious Pandas

Conflicts are honesty

When two branches change the same lines, git stops and asks you. Read the markers, choose, and finish a real merge.

14 min+35 XP for finishing

A merge conflict feels like something broke. Nothing did. Git found two changes to the same lines on two branches, and it refuses to guess which one you meant. That refusal is the safest thing git does all day.

Git merges line by line. Lines that only one side changed are taken automatically. Git stops only when both sides changed the same stretch, or neighbouring lines with nothing unchanged between them. Then it writes both versions into the file between markers:

<<<<<<< HEAD
apples
=======
pears
>>>>>>> snack

The part above ======= is your current branch (HEAD). The part below is the branch you’re merging in. You edit the file to say what it should say, delete the markers, git add the file to mark it resolved, and commit.

Resolve a real one

On main someone replaced “leaves” with “apples”. On snack someone replaced the same line with “pears”. Merge them and decide.

The menu argumentreal git hashes
Working tree
    Staging area
      Last commit
        Commit graph

        No commits yet.

        Check yourself+10 XP

        Main changes line 2 of a file. Your branch changes line 9 of the same file. Will merging conflict?

        Check yourself+10 XP

        You fixed the file and removed the markers. git commit still refuses. What did you probably forget?

        Do it for real · your machine+50 XP bonus

        Everything above ran in your browser. Now do it on a real cluster withthe tilt platform. You need Docker, kind and Tilt, about 15 GB of free disk and 8 GB of spare RAM. Setup guide · Can my machine run it?

        git init menu && cd menu
        printf "bamboo\nleaves\nshoots\n" > menu.txt && git add . && git commit -m menu
        git branch snack
        sed -i.bak 's/leaves/apples/' menu.txt && git commit -am apples
        git switch snack
        sed -i.bak 's/leaves/pears/' menu.txt && git commit -am pears
        git switch main && git merge snack
        cat menu.txt
        Self-reported. We can't see your machine, and we don't want to. This is a bonus, never required.

        Sources

        Finished reading?

        Missions and quizzes above earn their own XP. This marks the lesson done.