Creating Branches
Branches let you work on different features or fixes in isolation.
What is a Branch?
A branch is simply a pointer to a commit. When you create a branch, Git creates a new pointer - it doesn't copy any files.
Viewing Branches
Creating Branches
Create a New Branch
git branch feature-login
Create and Switch
git checkout -b feature-login
# or (newer syntax)
git switch -c feature-login
Branch Commands
| Command | Description |
|---|---|
git branch | List local branches |
git branch -a | List all (including remote) |
git branch <name> | Create branch |
git branch -d <name> | Delete branch |
git branch -D <name> | Force delete branch |
git branch -m <new> | Rename current branch |
How Branches Work
feature
↓
A---B---C
/
--o---o---o main
Both main and feature are just pointers to commits.
Branch Naming Conventions
Good branch names:
feature/user-authenticationbugfix/login-errorhotfix/security-patchrelease/v2.0
Avoid:
my-branchtestnew
Best Practices
- Keep branches focused: One feature per branch
- Use descriptive names:
feature/add-searchnotnew-stuff - Delete merged branches: Keep repository clean
- Branch from main: Start features from stable code
Exercise: Create a Branch
Create a new branch called feature:

