Code / Command Line & Git / Unit 4: Branches & merging

Merging branches Branches merge करना

Lesson 10 of 12 · about 14 minutes · Fast-forward merges and three-way merges with a merge commit.

⚡ 0 XP

Step 1 of 2

Fast-forward merge

samosa (branch)mainmerge

The winter menu is ready. Bring it into main with merge: first switch to the branch that should receive the work (main), then git merge winter-menu.

If main has not moved since the branch started, git simply slides main forward to the newest commit. That is a fast-forward — no new commit needed.

🎯 Challenge: Serve the winter menu +15 XP

You are on main. Merge the winter-menu branch into it with git merge winter-menu (you should see Fast-forward), then run git log --oneline.

Try twice to unlock the solution (0/2)

terminalCtrl ⏎

A safe practice terminal. Type a command and press Enter. Type help to list commands. Tab completes names, ↑ recalls the last command.

Files · ~ = /home/asha
  • chai-site/ ← you are here
  • menu.txt
Git timeline
mainwinter-me…c3e49a3 Add menuAdd menuHEAD→maind79e54f Add winter menuAdd winter …winter-menu
Checklist

Press Run to check your code.

  • You are on main
  • main now has winter.txt
  • It was a fast-forward
Lesson notes (text version)

1. Fast-forward merge

The winter menu is ready. Bring it into main with merge: first switch to the branch that should receive the work (main), then git merge winter-menu.

If main has not moved since the branch started, git simply slides main forward to the newest commit. That is a fast-forward — no new commit needed.

Challenge: Serve the winter menu

You are on main. Merge the winter-menu branch into it with git merge winter-menu (you should see Fast-forward), then run git log --oneline.

2. Three-way merge

Often both roads move: you commit opening hours on main while your friend adds snacks on snacks. Now git cannot just slide forward.

Git looks at three snapshots — the common starting point and both branch tips — and combines the changes. It records the result as a merge commit, a special commit with two parents. If the changes are in different files (or different parts), git does it all by itself.

Challenge: Snacks meet opening hours

On main you added hours.txt; on the snacks branch someone added snacks.txt. While on main, run git merge snacks to create a merge commit, then git log --oneline to see it.

Search by task, format or tool name.