Python Branching, Fast-Forward & 3-Way Merging
A branch in Git is simply a lightweight 41-byte movable pointer referencing a commit SHA. Switching branches (git switch / git checkout) updates HEAD and the working tree. Merging integrates divergent branch histories via Fast-Forward or 3-Way merge commits.
"A branch is a bookmark in a book: creating a branch does not duplicate the book, it simply places a new sticky note on the current page."
Deep Dive: How It Works
HEAD Reference: A special pointer indicating which local branch is currently checked out.
Fast-Forward Merge: If target branch has no divergent commits, Git simply slides the pointer forward.
3-Way Merge: If branches diverged, Git finds the common ancestor and creates a new merge commit with 2 parents.
Syntax Blueprint
git switch -c feature/auth # Work & commit git switch main git merge feature/auth
Create and switch to feature branch, commit changes, return to main, and merge.
Core Rules to Remember



Common Beginner Traps & How to Fix Them
Using git checkout for both branch switching and file restoration, causing accidental file overwrites.Why it happens: Legacy checkout had overloaded responsibilities.
How to fix: Use git switch for branches and git restore for discarding working directory changes.
Live Interactive Example
Hit Run Code to see it liveYour Turn: Micro Challenge
No pressure! Edit the starter code below and test your solution with instant feedback.
Create and Merge Feature Branch
Create and switch to a new branch named "feature/metrics".
Add a file metrics.log with content "cpu: 40%".
Stage and commit with message "feat: add metrics tracking".
Switch back to main and merge feature/metrics.
Finished reading and practicing?
Mark this lesson as completed to update your course progress.