Skip to content
Justice Tech School

Branches

A branch is a movable pointer to a commit. Create one with git switch -c name and move between them with git switch. Branches are cheap, so make one for every feature.

Example
echo base > a.txt; git add .; git commit -q -m "base"
git branch
git switch -q -c feature
echo more >> a.txt; git commit -q -am "feature work"
git branch
git switch -q main
git log --format=%s
git switch -q feature
git log --format=%s

Result

* main
* feature
  main
base
feature work
base

Exercise

Create and switch to a branch.

git switch  feature

Quiz Test

What is a branch?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.