← Back to Mission Control

Parallel Timelines

12 min read

Git Branching

Mission Phase 18 • Difficulty: Intermediate

Creating Alternate Realities

Branching lets you diverge from the main timeline to experiment, develop features, or fix bugs—all without affecting the stable code. It's Git's killer feature.

What is a Branch?

A branch is a lightweight movable pointer to a commit. The default branch is main (or master). Creating a branch costs nothing and takes milliseconds.

Why Branch?

Viewing Branches

git branch          # List local branches
git branch -a       # List all branches (including remote)
git branch -v       # Show last commit on each branch

Creating a Branch

git branch feature-navigation

This creates a new branch but doesn't switch to it.

Switching Branches

git checkout feature-navigation

Or with newer Git:

git switch feature-navigation

Create and Switch in One Command

git checkout -b feature-propulsion
# Or
git switch -c feature-propulsion

Branch Naming Conventions

Common patterns:

Use descriptive names. Avoid spaces and special characters.

Working on a Branch

  1. Create and switch: git switch -c my-feature
  2. Make changes and commit normally
  3. Push branch: git push -u origin my-feature

These commits only affect your branch, not main.

Deleting Branches

After merging a feature:

git branch -d feature-name     # Safe delete (only if merged)
git branch -D feature-name     # Force delete

Delete remote branch:

git push origin --delete feature-name

Branch Workflow Example

Typical Feature Development

# Start on main
git switch main
git pull

# Create feature branch
git switch -c feature-sensors

# Work on feature (multiple commits)
git add sensors.js
git commit -m "Add temperature sensor"
git add sensors.js
git commit -m "Add pressure sensor"

# Push feature branch
git push -u origin feature-sensors

# Create pull request on GitHub
# After approval and merge, clean up
git switch main
git pull
git branch -d feature-sensors

Viewing Branch History

git log --oneline --graph --all

Visualizes all branches and their relationships.

Comparing Branches

git diff main..feature-branch

Renaming Branches

git branch -m old-name new-name

Branch Best Practices

Next: Timeline Convergence

You can create parallel timelines. Now learn to merge them back together!