Lesson 19 +25 XP

Project 2: Feature Branches

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

git branch

You should see main (marked with a *).

Step 3: Create a feature branch

git switch -c feature-dark-mode

Step 4: Make changes

Edit index.html to add a dark mode style:

<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

git add .
git commit -m "Add dark mode"

Step 6: Switch back to main

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

git merge feature-dark-mode

Step 8: Clean up

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.