Git · Lesson 3 of 6
Branches & merging
Creating branches, switching, merging and resolving conflicts.
A branch is an independent line of work. Build a feature on its own branch, keep main stable, and merge when it's ready.
git switch -c feature/login— create and move to a new branch.git branch— list branches (the * marks the current one).git merge feature/login— bring that branch's commits into the current branch.
Merge conflicts
If both branches changed the same lines, Git stops and marks the file with <<<<<<<, ======= and >>>>>>>. Edit the file to the correct final version, remove the markers, then git add and git commit.
Example in the terminal
Run these on your own computer$ git switch -c feature/salary-filter
Switched to a new branch 'feature/salary-filter'
$ git add filter.js
$ git commit -m "Add salary range filter"
$ git switch main
$ git merge feature/salary-filter
Updating 3f2c1aa..8b41d07
Fast-forward
filter.js | 24 ++++++++++++++++++++++++
$ git branch -d feature/salary-filter
Deleted branch feature/salary-filter
Lines starting with $ are commands you type; the rest is what Git prints. Names and URLs are examples.
Key points
- One branch per feature or fix.
- Merge back into main when done.
- Conflicts = same lines changed; edit, add, commit.
Quick check
Which command creates and switches to a new branch?
git switch -c creates the branch and moves you onto it (older equivalent: git checkout -b).
Practice task
Make a branch, change one line of README.md there, change the same line differently on main, merge, and resolve the conflict.
Interview corner
Merge vs rebase?
Merge joins histories with a merge commit and keeps the true timeline. Rebase replays your commits on top of another branch for a straight history — but don't rebase commits others already pulled.
What is a fast-forward merge?
When main has no new commits since the branch started, Git just moves main's pointer forward — no merge commit is needed.
Further reading
Official documentation, linked for deeper study. These are outside sites; this lesson's text is our own.
Original lesson written by the InfoparkDaily team · © 2026 InfoparkDaily · Free to learn — no paid course or subscription.