>_ IzzyLab

Hands-on task

This task is step 7 of the course “Git: first commits”

Your first branch

easy~5 min

The /root/site repository has a main branch, main. A new page has to be built in a separate branch, and main should be left alone for now.

  1. Create a contacts branch and switch to it.
  2. In this branch, create a file contacts.html (any contents, one line is enough) and commit it.

The main branch must have neither a new commit nor the contacts.html file.

What you'll practise:
  • git branch
  • git switch -c
  • branches

Topic breakdown

A branch is a separate line of history. In it you can calmly build a new feature while the main branch (usually main) keeps working. When everything is ready, the branch is merged back into main — that's for the next courses.

Under the hood, a branch is just a movable label pointing at a commit. Every new commit is added to the current branch, and its label moves forward.

git branch                # list of branches, * marks the current one
git switch -c experiment  # create the experiment branch and switch to it
git switch main           # go back to main

When you switch between branches, git replaces the files in the directory with the ones saved in that branch. So it's best to commit your changes before switching.

What's checked

  1. Branch contacts created
  2. The contacts branch has a commit with contacts.html
  3. The main branch is untouched

What it looks like