Branching & Merging — Work in Parallel
Lesson opener
In one line: Branches as movable pointers to commits.
Why it matters: This shows up at work when you need to branches as movable pointers to commits.
Before this lesson: History & undo
Before you start
| Resource | Link |
|---|---|
| Previous | History & undo |
| Next | GitHub essentials |
| Time | ~55 minutes |
What you will learn
- Branches as movable pointers to commits
git branch,git switch,git merge- Resolve merge conflicts step by step
- Merge vs rebase — when teams use each (2026 default: merge for beginners)
Section 1 — Why branches exist
Plain English: main should stay deployable. New work happens on feature branches — if the experiment fails, delete the branch; main is untouched.
Section 2 — Create and switch branches
Modern Git (2.23+):
git switch -c feature/add-readme
# work, commit...
git switch main
git merge feature/add-readme
git branch -d feature/add-readmeLegacy equivalent: git checkout -b feature/add-readme
List branches:
git branch -aSection 3 — Merge conflicts — not a disaster
When two people edit the same lines, Git stops and asks you to choose:
<<<<<<< HEAD
Welcome to our site
=======
Welcome to My Portfolio
>>>>>>> feature/update-titleFix:
- Edit file — keep one version or combine both
- Remove
<<<<<<<,=======,>>>>>>>markers git addthe filegit commit(merge commit)
git status # lists conflicted filesSection 4 — Merge vs rebase (team rules)
| Merge | Rebase | |
|---|---|---|
| History | Preserves branch forks | Linear history |
| Safety | Safer for shared branches | Never rebase public main |
| Learner default | ✅ Use this | Learn after merge is solid |
# Rebase (only on YOUR feature branch before PR)
git switch feature/my-work
git rebase mainSection 5 — Branch naming conventions (2026)
| Pattern | Example |
|---|---|
| Feature | feature/user-login |
| Bugfix | fix/null-pointer-report |
| Docs | docs/update-readme |
| Release | release/v2.1.0 |
Avoid: test, john, new-stuff
Practice
- On
main, createfeature/footer - Add a line to README, commit
- Switch to
main, change the same line differently, commit - Merge
feature/footerintomain— resolve conflict manually
Checklist
- [ ] I created and merged a feature branch
- [ ] I resolved a merge conflict
- [ ] I know not to rebase shared
main
Teacher walkthrough: feature branch to merge
All figures illustrative.
Step 1 — Branch from updated main. Name for the change (feature/fill-rate-kpi).
Step 2 — Commits small and focused on that branch only.
Step 3 — Merge or rebase per team policy; resolve conflicts deliberately (open both sides, keep intent).
Step 4 — Delete branch after merge when appropriate; keep main releasable.
Failure example: days of work on main
Symptom: Broken main blocks everyone; hard to review.
Diagnosis: No feature branch; mixed unrelated commits.
Correction: Branch per task; PR review (git6); protect main.
Validation: Main stays green; feature isolated in log.
Guided practice
Conflict markers appear in report.md. What must you remove before committing?
Complete solution: All conflict marker lines; keep the intended final text only; test/build after.
Independent practice
Acceptance criteria:
- Feature branch created and committed to.
- Merge (or documented PR merge) completed.
- One conflict resolved without leaving markers.
- Main/work branch relationship explained in two sentences.
Common mistakes
- Long-lived branches that never merge.
- Committing conflict markers.
- Rewriting shared branch history casually.
What's next
GitHub essentials — put your repo online: clone, push, pull, README.