Merging and Conflicts · practice
Merge a Branch That Does Not Conflict
An unfinished conflict can make every merge look like an argument waiting to happen. Most merges are quieter: Git either moves a
So before you resolve the prepared conflict, you are going to make two merges of your own that go through without incident. Both use only commands you already have.
Your main with a clean working tree. If git status reports a merge in progress, end it with git merge --abort from the previous lesson before you begin.
git status
A branch that is only ahead
Make a branch, put one main where it is:
git switch -c opening-note
nano -w hours.txt
Type this one line, then save with Ctrl-O, Enter, and leave with Ctrl-X:
Open 9:00 to 17:00, Tuesday to Saturday.
Commit it, then go back to main:
git add hours.txt
git commit -m "Add the opening hours"
git switch main
main has not moved since opening-note started, so opening-note is simply farther along the same line. That is the fast-forward shape from lesson 1. Merge it:
git merge opening-note
git log
Read what Git printed. It says Fast-forward, and git log has one more commit than before rather than two. No merge commit was created, because none was needed: Git moved the name main forward along commits that already existed.
Two branches that both moved
Now arrange the other shape deliberately. Start a second branch and commit on it:
git switch -c contact-note
nano -w contact.txt
Enter this line, then save and exit as before:
Questions: hello@example.invalid
git add contact.txt
git commit -m "Add a contact line"
git switch main
This time, commit something on main as well, so that neither branch contains the other’s work:
nano -w notice.txt
Enter this line, then save and exit:
The shop is closed on public holidays.
git add notice.txt
git commit -m "Note the holiday closure"
git merge contact-note -m "Merge the contact line"
git log
Git could not move a pointer this time, because main had a commit that contact-note lacked and the other way round. It built the two-parent commit from lesson 2 instead. The -m option supplies that merge commit’s message, the same way it does for an ordinary commit.
Both branches changed different files, so Git combined them without asking you anything. That is the ordinary case, and it is worth noticing how unremarkable it felt.
What made these two merges quiet
Nothing about the prepared conflict has changed while you did this. simplify-tiers still disagrees with main about the same three lines of pricing.md, and merging it will still stop.
The difference is not luck and it is not the size of the change. The common text-conflict case is that both sides changed the same lines, so no combination is obviously the one you meant. Git can also stop for other incompatible changes, such as one side deleting a path the other side edited. Different files merge quietly, and different parts of one file usually merge quietly too.
Your two branches added contact.txt and notice.txt, and Git merged them without asking you anything. Why?
After git merge opening-note, Git reported Fast-forward and the history gained one commit rather than two. What does that tell you?
You have now completed two merges and read the shapes in your own history. That is the normal experience of merging. The next lesson returns to the prepared disagreement, which is the other, less common experience, and it is the reason the chapter exists.