Rana Maninder Singh
Lesson 4 of 8Git & GitHub

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

ResourceLink
PreviousHistory & undo
NextGitHub 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-readme

Legacy equivalent: git checkout -b feature/add-readme

List branches:

git branch -a

Section 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-title

Fix:

  1. Edit file — keep one version or combine both
  2. Remove <<<<<<<, =======, >>>>>>> markers
  3. git add the file
  4. git commit (merge commit)
git status   # lists conflicted files

Section 4 — Merge vs rebase (team rules)

MergeRebase
HistoryPreserves branch forksLinear history
SafetySafer for shared branchesNever rebase public main
Learner default✅ Use thisLearn after merge is solid
# Rebase (only on YOUR feature branch before PR)
git switch feature/my-work
git rebase main

Section 5 — Branch naming conventions (2026)

PatternExample
Featurefeature/user-login
Bugfixfix/null-pointer-report
Docsdocs/update-readme
Releaserelease/v2.1.0

Avoid: test, john, new-stuff


Practice

  1. On main, create feature/footer
  2. Add a line to README, commit
  3. Switch to main, change the same line differently, commit
  4. Merge feature/footer into main — 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:

Common mistakes

  1. Long-lived branches that never merge.
  2. Committing conflict markers.
  3. Rewriting shared branch history casually.

What's next

GitHub essentials — put your repo online: clone, push, pull, README.