Difficulty: Beginner
Estimated Time: 10 minutes

In this scenario you will learn how you can create branches in your repository. A branch allows you to work, in effectively, a brand new working directory. The result is that a single Git repository can have multiple different versions of the code-base, each of which can be swapped between without changing directories.

The default branch in Git is called master. Additional branches allow you to perform the same operations and commands as you would on master, such as committing, merging and pushing changes. As additional branches work in the same way as master they are ideal for prototyping and experiments as any changes can be merged to master if required.

When you switch a branch, Git changes the contents of the working directory. This means you don't need to change any configurations or settings to reflect different branches or locations.

This environment has been configured with a repository with a remote origin repository defined.

In this scenario we've explored how you can work with branches which are ideal for prototyping and experiments as they can be quickly created and thrown away.

This scenario has been added to your scrapbook where you can review the examples and commands you executed.

Don’t stop now! The next scenario will only take about 10 minutes to complete.

Scenario 6 - Experiments Using Branches

Step 1 of 5

Step 1 - Git Branch

Creates are created based on another branch, generally master. The command git branch <new branch name> <starting branch> takes an existing branch and creates a separate branch to work in. At this point both branches are identical.

To switch to a branch you use the git checkout <new branch name> command.


Create and checkout a new branch called 'new_branch'


The command git checkout -b <new branch name> will create and checkout the newly created branch.