gitpractice.dev

brewly — Ch.2 · Your first branch

Exercise 1 of 7

Before you start

What is a branch?

A branch is a movable name pointing at a commit. New commits move the branch you are on, so your work stays separate from main until you merge it.

Teams often name branches after their purpose, such as feature/search-box.

git branch
list branches; * marks the one you are on
git switch -c <name>
create a branch and switch to it
git switch <name>
switch to a branch that already exists

Committing on your branch

The "Write the code" button edits the files. Stage and commit as usual; the commit goes to the branch you are on.

git status
which branch am I on, and what changed?
git add <file>
stage a file
git commit -m "What you did"
commit it
You can reopen this any time with “Lesson”.

Continue on a desktop

Typing git on a small screen is no fun. Open this page on a laptop or desktop to practise.

Back to the path