Skip to content

Help us create more tutorials! Make a donation using the Donate button or become a member using the button below to hide this banner and track your progress.

Create a branch – Git

Summary

To create a branch in Git and switch to it, enter the following command in your terminal:

git checkout -b branch-name

Details

The above command will create a new branch and switch to it automatically.

To check that you’ve created and switched to the new branch, enter the following command in your terminal:

git status

The branch you’re currently on should print out on the next line.

You can also list all of your branches available by entering the following command in your terminal:

git branch

The branch you’re currently on will be marked with an asterisk, as in the example below:

  master
* topic-branch

Exercises

Run the following command to create a branch called dev-branch in your project folder:

git checkout -b dev-branch

Add some code to the index.html file and then stage and commit the changes.

References

Basic Branching and Merging from the Pro Git book

Back to: Git Course > Git Intermediate