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.

Scenario 6 - Experiments Using Branches

Step 1 of 5

Step 1 - Git Branch

Branches 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.

Task

Create and checkout a new branch called 'new_branch'

Protip

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

This tab will not be visible to users and provides only information to help authors when creating content.

Creating Katacoda Scenarios

Thanks for creating Katacoda scenarios. This tab is designed to help you as an author have quick access the information you need when creating scenarios.

Here are some useful links to get you started.

Running Katacoda Workshops

If you are planning to use Katacoda for workshops, please contact [email protected] to arrange capacity.

Debugging Scenarios

Below is the response from any background scripts run or files uploaded. This stream can aid debugging scenarios.

If you still need assistance, please contact [email protected]