Command Shift

Branching

Branches are the key piece of git. They allow us all to work in the same project, and same files, at the same time. The main branch of your project is often called master or main (we changed the config earlier, so ours should be main).

Every time you want to add a new feature to your project, or even fix an existing one, you should create a new branch:

git switch -c branchName

This is the preferred way to create a branch, it can also be done with the checkout command (though this is being deprecated):

git checkout -b branchName

This new branch, will be an exact copy of your main one. Once created, you can change your code freely, which then gets pushed, code reviewed and finally merged.

The below images can be used as a visualisation of what happens to the Git repo when you create and merge a branch:

creating a new branch merging branch

On this page

No Headings