Lesson 11 / 26

Creating & Switching Branches

git branch and git switch/checkout in practice.

List, create, switch

git switch -c creates and moves to a new branch in one step — the modern replacement for checkout -b.

git branch                 # list branches
git switch -c feature/login
# equivalent older form:
git checkout -b feature/login

Output:

Switched to a new branch 'feature/login'

Rename & delete

-d deletes a merged branch safely; -D force-deletes even if it has unmerged work.

git branch -m old-name new-name
git branch -d feature/login    # safe delete
git branch -D feature/login    # force delete

switch vs checkout

git checkout does too many things (branches and files). git switch and git restore split those jobs apart and are easier to reason about.