Branches & Switching
Create, switch, and delete branches to work on features in isolation
Knowledge Debt detected
You can study this freely — but your score may plateau if these foundations have gaps. The Mastery badge requires them to be solid.
Explanation
A is how Git lets multiple people (or ideas) develop in parallel without stepping on each other.
Create a branch
git branch feature-login # creates the branch
git switch feature-login # moves you onto it
# shortcut:
git switch -c feature-login # create + switch in one commandList branches
git branch # local branches (* marks current)
git branch -a # local + remote branchesDelete a branch
git branch -d feature-login # safe delete (only if merged)
git branch -D feature-login # force delete (even if unmerged)The main branch is usually called main (modern) or master (legacy). Never commit experimental work directly to main.
Examples
Start a feature branch
Creating a branch before starting any work is the standard team workflow — it keeps main clean and your work reviewable.
# You are on main
git switch -c add-search-bar # create + switch
# ... make changes ...
git add .
git commit -m "feat: add search bar to header"
git switch main # go back when doneList and clean up branches
Deleting merged branches keeps the repo tidy. Use -D only when you are sure you no longer need the work.
git branch
# * main
# add-search-bar
# fix-login-bug
git branch -d fix-login-bug # delete after merging
git branch -a # see remote branches tooHow well did you understand this?
Next in Git & Version Control
Merging & Conflict Resolution