Skip to content

Try our new Crash Courses!

Buy one of our new Crash Courses, now hosted on Teachable.

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 Reference > Git Intermediate