Skip to content
CodeItRaw
Git Basics

Lesson 2/4

A branch is the history moving forward on a separate line. When you try out a new feature you do not want to break the main branch (main): you open a branch and commit there, and main stays where it is, in working order.

git branch
git switch -c fix/login
git add login.py
git commit -m "Fix empty password check"
git switch main
git branch lists the branches and marks the one you are on with a star. git switch -c name opens a new branch and moves to it; git switch name moves to one that exists. Commits are added to the branch you are on at that moment.

A branch is really a very light thing: a label pointing at a commit. Opening one copies nothing. When you switch branches the files in the folder go back to how they are in that branch's last commit; on moving to main the file you added on the other branch disappears from view, but it is not deleted: it is on its branch.

Tasks

Tasks open in order. Solve them all and the next lesson opens.

This lesson's tasks open when the lessons before it are finished. You can read the explanation now.

  1. 01

    Create a branch

    Git task

  2. 02

    Work on a branch

    Git task

If you would rather not wait for the order, every problem is open without locks: Problem list