Branches and merging · Lesson 5 of 15
Branches and HEAD
A branch is a movable name, and HEAD says where you are.
A branch is not a full copy of your files; it is a lightweight name pointing to a commit. Every new commit advances the current branch. HEAD normally points to that branch, telling Git which name should move.
A: start
B: login ← main
C: tests ← feature ← HEAD
Branches are names on commits; the commits are shared.
git init -q -b main echo "base" > app.txt git add app.txt git commit -q -m "Base" git switch -q -c feature echo "feature" >> app.txt git commit -q -am "Build feature" git branch -v
git switch -c feature creates a branch at the current commit and moves HEAD to it. git switch main updates files to match main's snapshot. Commit or stash first if local edits would conflict.
Quick question
What moves when you commit on feature?
Exercise
Start with a commit on main, create and switch to feature, then list branches.
* feature main
git init -q -b main echo "base" > app.txt git add app.txt git commit -q -m "Base" git branch
Learn more from
Played 0 of 2 games
Sign in to save your progress and earn XP.