ILILCode
HomeGitBranching

Branches: parallel versions of the same project

Create a branch for the next idea, switch between them, and delete it when you are done.

Lesson 6 of 9 in Git8 min1 exercise

A branch is a movable pointer to a commit. Creating one costs almost nothing and changes no files — it just gives you a name for a line of work.

Create, switch, clean up
git branch                 # list branches, * marks where you are

git switch -c feedback     # create + switch (Git 2.23+)
git checkout -b feedback    # the older equivalent

git switch main

git branch -d feedback     # delete a merged branch

switch is the modern command for changing branches; checkout still works and does more than one job. Use switch for branches and restore for files, and the intent stays obvious.

Exercises

Checked in your browser · hints and solutions included

01

Exercise

Create and switch

Create a new branch called feedback and switch to it in the same command.

terminal