Loading lessons...
Project 2: Feature Branches
Practice the branching workflow that teams use every day.
Step 1: Start from a working repo
Use the project from Project 1, or make a fresh one with a few commits.
Step 2: Check your branch
bash
git branch
You should see main (marked with a *).
Step 3: Create a feature branch
bash
git switch -c feature-dark-mode
Step 4: Make changes
Edit index.html to add a dark mode style:
html
<body style="background:#111; color:#fff">
<h1>Welcome to my blog</h1>
<p>Dark mode is here!</p>
</body>
Step 5: Commit on the branch
bash
git add .
git commit -m "Add dark mode"
Step 6: Switch back to main
bash
git switch main
Notice your file went back to the old version. The dark mode work is safely on its own branch.
Step 7: Merge the feature
bash
git merge feature-dark-mode
Step 8: Clean up
bash
git branch -d feature-dark-mode
TL;DR
- Create branches with
git switch -c. - Switch with
git switch. - Merge finished work with
git merge. - Delete merged branches with
git branch -d.