CurriculumBranching & MergingCreating & Switching Branches
Lesson 2 of 540%
Beginner7 min+70 XP

Creating & Switching Branches

Creating a branch takes milliseconds — it is just a 41-byte pointer file. Switching updates your entire working directory to reflect that branch's state. Git performs both operations with incredible speed regardless of project size.

01.Branch Naming Conventions

Use lowercase hyphenated names with descriptive prefixes: feature/ for new features (feature/user-auth), fix/ or bugfix/ for bug fixes (fix/login-crash), hotfix/ for urgent production fixes (hotfix/xss-patch), release/ for release prep (release/v2.0), chore/ for maintenance (chore/update-deps). Always be descriptive — "my-branch" tells teammates nothing.

Branch Visualization
featuremainHEAD
main
feature
HEAD

02.checkout vs switch

git checkout <branch> is the classic command — it does many things (switch branches, restore files). git switch <branch> is the modern alternative added in Git 2.23 specifically for switching branches. Both work identically for this purpose. git checkout -b and git switch -c both create AND switch in one step.

Commit Timeline
a1b2c3d
init
b2c3d4e
feat
c3d4e5f
fix
d4e5f6a
HEAD

Commands

commands — click to reveal output
$
git branch feature/login
Create branch (stays on current branch)
$
git checkout feature/login
Switch to the new branch
▼ show output
$
git checkout -b feature/signup
Create AND switch in one command (classic)
▼ show output
$
git switch feature/login
Switch branches — modern syntax (Git 2.23+)
$
git switch -c feature/dashboard
Create AND switch — modern syntax
▼ show output
$
git branch -d feature/login
Delete a fully merged branch safely
▼ show output
$
git branch -D feature/experiment
Force-delete even if not merged (data loss warning)
$
git branch -m old-name new-name
Rename a branch
KNOWLEDGE CHECK

What does git checkout -b feature/x do?

Rate this lesson:
PreviousNext Lesson