Branching

This YouTube video was created by GitHub Training & Guides.

A branchopen in new window is a divergence from the main line of development. In other words, if a Git repository is a straight line, a branch is a second line that splits and runs parallel from the first.

Creating a Branch

In Git, a branch can be created using the git branchopen in new window command. While the git branch command accepts many optionsopen in new window, to create a new branch, follow the command with the desired name of the new branch.

git branch new-branch

Switching Branches

When the Git repository is first initialized, a default branch is created. This branch is usually called main or master (Learn How to set the name of the default branch). But once a second or multiple branches are created, it may become necessary to switch to an alternate branch. Switching can be accomplished by using the git checkoutopen in new window command.

git checkout new-branch