Version Control Mastery 45 min interactive guide⚔️ Live Graph & Conflict Simulator

Git Branching: Feature Workflows & Conflicts

Master Git branching strategies, isolated feature development, fast-forward vs 3-way merge commits, remote tracking branches, and resolving real-world merge conflicts step-by-step through a live animated Git Graph simulator.

01

1. What Is a Git Branch?

A Git Branchis simply a lightweight, movable pointer to a commit hash. Git doesn't copy your files when you create a branch; it merely creates a tiny 41-byte text file containing a commit SHA.

💡 Mental Model: Think of a branch as a bookmark in a book. Moving to a new chapter moves the bookmark, but the rest of the book remains untouched.
02

2. Why Do Developers Use Branches?

1. Isolation

Work on experimental features without breaking the working production application.

2. Parallel Work

10 developers can work on 10 different features simultaneously without stepping on each other's toes.

3. Code Reviews

Create a Pull Request for a specific branch so teammates can review before merging into main.

03

3. Understanding the Main Branch

The main branch represents the canonical, production-ready timeline of your software. Developers rarely commit directly to main; all changes flow through reviewed feature branches.

04

4. Creating a Branch (switch vs checkout)

# Modern recommended command (Git 2.23+):
git switch -c feature/login-page

# Equivalent older command:
git checkout -b feature/login-page

# List all local branches (active has *):
git branch
05

5. Working on a Feature Branch & Switching

When you switch branches with git switch main, Git modifies your local working directory files to match the snapshot of the selected branch.

07

7. Making Commits on a Branch

Every commit advances only the active branch pointer (pointed to by HEAD). Other branches stay at their previous commit positions.

08

8. Merging Branches: Fast-Forward vs 3-Way Merge

Fast-Forward Merge

Direct Linear History

When main hasn't moved since branching, Git simply slides main forward to the tip of the feature branch. No extra merge commit is created.

3-Way Merge Commit

Divergent Histories

When both main and feature have new commits, Git combines both histories by generating an explicit merge commit with two parent commits.

09

9. Handling Merge Conflicts Step-by-Step

When both branches modify the same line, Git stops and leaves conflict markers:

<<<<<<< HEAD (current branch: main)
const API_URL = "https://api.pathubs.com/v1";
=======
const API_URL = "https://api.pathubs.com/v2-beta";
>>>>>>> feature/api-upgrade (incoming branch)
🛠️ 4 Steps to Resolve: 1) Open the file, 2) Choose the correct code and delete markers, 3) Stage with git add, 4) Commit with git commit.
10

10. Deleting Local & Remote Branches

# Delete local branch safely (only if merged):
git branch -d feature/navbar

# Force delete local branch (unmerged changes lost):
git branch -D feature/navbar

# Delete remote branch on GitHub:
git push origin --delete feature/navbar
11

11. Remote Tracking Branches (origin/...)

# Push feature branch and track remote:
git push -u origin feature/auth

# Fetch all remote branches without merging:
git fetch origin

# Switch to a teammate's remote branch:
git switch feature/teammate-work
12

12. A Real-World Feature Branch Workflow

1. git switch main && git pull origin main
2. git switch -c feature/user-profile
3. Make edits, test, git add ., git commit -m "feat: profile card"
4. git push -u origin feature/user-profile
5. Open Pull Request on GitHub ➔ Code Review ➔ Merge into main
6. git switch main && git pull origin main
7. git branch -d feature/user-profile (clean up!)
13

13. Common Branching Mistakes

  • Forgetting which branch you are on: Always run git branch or use a terminal shell prompt with branch indicators.
  • Keeping long-lived stale branches: Merge frequently to avoid massive merge conflicts down the road.
  • Committing on detached HEAD: Make sure you switch to a named branch before making new commits.
14

14. Branching Best Practices

  • Use descriptive branch naming prefixes: feat/, fix/, refactor/, docs/.
  • Keep branches focused on single, self-contained features.
  • Delete branches immediately after they are merged into main.
LIVE INTERACTIVE LAB

Git Graph & Conflict Simulator

Watch Git branch pointers and commit histories evolve in real time. Create branches, make commits, switch active branches, simulate merge conflicts, and resolve them interactively!

VISUAL GIT GRAPH TIMELINE (Click node to inspect metadata):
mainHEAD
────
feature/navbar
\──────
TERMINAL LOG (Simulated Git CLI):
$ git switch main
Switched to branch 'main'
Active branches: main, feature/navbar
🎯 Branching Challenge 1 of 6✅ Completed!

Goal 1: Switch to the feature branch by clicking 'Switch to feature/navbar'.

Challenge Completed! You mastered Git branching & merge resolution for Goal 1!
TEST YOUR KNOWLEDGE

Git Branching & Merge Conflict Mastery Quiz

8 scenario-based questions testing your understanding of Git pointers, fast-forward vs 3-way merges, conflict resolution, and feature branch workflows.

Question 1 of 8Score: 0 / 8
🌿 What is a Git Branch at the technical implementation level?