~/hackweb.dev
Branching
Quiz
...

Branching

beginner · updated Tue Sep 08 2026Contribute

Create and switch between branches to work on features in isolation.

Branching

Branches let you develop features, fix bugs, or experiment in isolation without affecting the main line.

Creating a Branch

git branch feature

This creates a new branch called feature but stays on your current branch.

Switching Branches

git switch feature

Moves you to the feature branch. Your working directory updates to match.

Create and Switch in One Step

git switch -c feature

Creates the branch and switches to it immediately — the most common workflow.

Listing Branches

git branch        # local branches
git branch -a     # includes remote branches

The current branch is marked with *.

Deleting a Branch

git branch -d feature

Safely deletes after merging. Use -D to force delete unmerged branches.

Best Practices

  • Use short, descriptive branch names (feature/auth, fix/login-bug)
  • Keep main always deployable
  • Delete branches after merging
  • One feature per branch

Common Mistakes

  • Forgetting to switch branches before editing files
  • Creating branches from the wrong starting point
  • Not deleting stale branches
  • Working directly on main for new features