Branches: Working Without Fear
1 min read
What is a branch?
A branch is simply a movable pointer to a commit. The default branch is usually main. When you create a branch, you get an independent line of work — experiment freely without touching main.
git branch feature-login # create a branch
git switch feature-login # move onto it
# (or in one line)
git switch -c feature-login
Why branches matter
Imagine your main branch is the stable, working app. You need to add login but it might break things. So:
- Create
feature-login - Build and commit there
- When it works, merge it back into
main
If the experiment fails, just delete the branch — main was never affected.
git switch -c feature-login
# ...edit files...
git add .
git commit -m "Add login form"
git switch main
git merge feature-login # bring the work into main
Visualising it
main: A───B───C
\
feature: D───E
After merging, main includes D and E. Branches are cheap and fast in Git — use them for every feature or fix.