Working with Branches
Branches let you work on different features or fixes in isolation. The main branch is your stable codebase; feature branches are where you develop.
Example
# List branches
git branch
# Create a new branch
git branch feature-login
# Switch to a branch
git checkout feature-login
# Or (newer syntax):
git switch feature-login
# Create and switch in one command
git checkout -b feature-signup
# Or:
git switch -c feature-signup
# Delete a branch (after merging)
git branch -d feature-login Branch Workflow
A typical workflow: create a branch, make changes, commit, then merge back into main.
Example
# 1. Start from main
git switch main
# 2. Create feature branch
git switch -c add-navbar
# 3. Make changes and commit
git add .
git commit -m "Add responsive navbar"
# 4. Switch back to main
git switch main
# 5. Merge the feature
git merge add-navbar
# 6. Delete the branch
git branch -d add-navbar Branch Naming Conventions
Consistent branch naming makes collaboration easier.
- feature/add-login — new features
- bugfix/fix-header — bug fixes
- hotfix/security-patch — urgent production fixes
- chore/update-deps — maintenance tasks
- docs/update-readme — documentation changes
