Branching: Creating, Switching & Deleting

💻 GitLesson 6Beginner

Branching creates dynamic sandbox paths for features or bug fixes, keeping modifications isolated from the main production code.

1 Branch Commands
Shell — Branch Management
# List all local branches (starred is current)
git branch

# Create a new branch
git branch feature-login

# Switch your active workspace to that branch
git checkout feature-login
# Or use the modern switch command:
git switch feature-login

# Create and switch to a new branch in a single command
git checkout -b feature-payment
git switch -c feature-payment

# Delete a branch (only if merged)
git branch -d feature-login

# Force delete an unmerged branch
git branch -D feature-login
2 Code Challenge
Challenge: Create a branch named feature-about, switch to it, add a new file about.html, and commit it on that branch. Switch back to main and confirm the file is not present.