Git: Create new branch from master

You have the master of your beautiful project.

Everything works and your program manages the production of your robot army in a sublime way.

Now you are asked, by others or by the dissatisfied part of your brain, to add a feature.

A feature, however small it may be, could cause problems, and interrupt the working flow of the master, which may already be in production.

The solution is to use git to create a new branch from master, a separate magical place, where to work freely, without being afraid of breaking everything.

How to create a new branch?

Move to your project folder, with your glittering console, and type:

git branch branch_name

You just created a new branch, provided that no “branch_name” already existed.

Now don’t forget to switch to the new branch (checkout) via:

git checkout branch_name

Create a new branch and checkout

There is a shortcut to save the 0.5 seconds required by the above method:

git checkout -b branch_name

With this command you will generate the new branch and together you will move inside it.

Doubts? Feel free to leave a comment!