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.
Scenario 6 - Experiments Using Branches
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.
Create and checkout a new branch called 'new_branch'
git checkout -b <new branch name> will create and checkout the newly created branch.