Every commit so far in this course happened on one line of history. A branch lets development split — trying a new feature, fixing a bug, or experimenting — without touching the working version until it's ready.
A new repository starts with one branch, conventionally named main (older projects sometimes use master) — the project's stable, working line of history.
git branch feature-login
# Creates the branch, but doesn't switch to it yetgit switch feature-login
# or, the older equivalent still seen everywhere:
git checkout feature-logingit switch -c feature-login
# or
git checkout -b feature-logingit branch
# main
# * feature-login <- the asterisk marks the current branchCommits made while on feature-login only exist on that branch — switching back to main makes those changes disappear from view (not deleted, just not part of main's history) until the branch is merged, covered in the next lesson.
git switch feature-login
# ... make changes, git add, git commit ...
git switch main
# The feature-login commits aren't visible here yet# Safe delete — refuses if the branch has unmerged changes
git branch -d feature-login
# Force delete, even with unmerged changes
git branch -D feature-loginBranch liberally
Creating a branch for every real change — even a small one — costs almost nothing and keeps main always in a working state. This habit alone prevents most of the "I broke everything" moments a beginner runs into.