0%

Merging and Conflicts · practice

Resolve a Merge Conflict

You have opened a in the middle of a . main added a solo tier and chat support. At the same time, simplify-tiers raised the Standard and Team prices. Both changes are useful, and pricing.md contains both marked alternatives. Your task is to turn them into one deliberate result and finish the merge.

This lesson starts correctly from the untouched chapter seed, so you can arrive here directly without completing the earlier lessons. If you have worked through them, your main also carries the two merges you made in lesson 4, and nothing below changes because of it.

Confirm the paused merge

Start with the plain command that describes the repository’s current state:

git status

There are two possible answers here, and both are fine.

If it reports unmerged paths and names pricing.md, the merge is already paused and you can move straight to the next section. That is what you see when you arrive at this lesson directly.

If it reports a clean working tree instead, the merge is simply not running yet, which is where the earlier lessons in this chapter leave off. Start it now:

git merge simplify-tiers
git status

git merge brings the named into the branch you are on, which is main. Git stops on pricing.md and reports it as an unmerged path, exactly as described in lesson 3.

Decide what the final file should say

The business decision is specific: keep the Solo tier and chat support from main, and use the raised Standard and Team prices from simplify-tiers. The resolved file should be:

# Pricing

Solo: 12 per month
Standard: 25 per month
Team: 75 per month
Support: email, and chat on Team

That result matches neither parent. It combines an intentional part of each, which is the work Git needed a person to do.

Open the file in nano:

nano -w pricing.md

-w keeps nano from inserting hard line breaks in a narrow . Edit the file until it contains the result above. Remove all three marker lines as well as the unwanted alternative lines. Save with Ctrl-O, press Enter to confirm pricing.md, then leave with Ctrl-X.

Mark the decision as resolved

Saving the file changes its bytes, but Git still treats the path as unmerged until you stage the resolution. git add pricing.md puts the resolved file into the and tells Git that this conflict has been decided.

git add pricing.md
git status

The second command should no longer list unmerged paths. Instead it says that all conflicts are fixed but the merge is still in progress. This state is worth seeing: staging finishes the file decision, not the merge itself.

Complete the merge commit

git commit completes the paused merge by creating its two-parent . The option -m supplies the quoted commit message directly instead of opening an editor.

git commit -m "Merge simplified pricing tiers"
git status

The final git status should report a clean working tree and no merge in progress. The new commit’s first parent is the old tip of main; its second parent is the tip of simplify-tiers. The unrelated index.html stayed exactly as it was.

If you want to repeat the exercise after completing the merge, do this only in the practice repository:

git reset --hard HEAD~1
git merge simplify-tiers

The hard reset removes the merge commit and restores tracked files to its first parent. Both branches remain, so the second command recreates the same conflict. This discards later uncommitted work too, which is why it belongs only in this disposable practice repository.

You removed every conflict marker and saved pricing.md. Why do you still run git add pricing.md?

A conflict is now a procedure you can repeat: read git status, inspect the marked alternatives, edit one intended result, stage each resolved path, commit the merge, and check that the tree is clean. If you are not ready to decide, abort and return to the pre-merge state. Nothing in that sequence requires panic or discarded work.