Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Development Tools Git Basics Working With Remote Repositories Pushing and Pulling

Jaime Sandoval
Jaime Sandoval
7,083 Points

Why use git checkout for the new feature branch when the git branch -b new_feature automatically switches it?

“git branch -b new_feature” should place him in the new_feature branch automatically. So why, after creating the branch with said command, is he in the master branch when he runs “git branch”to view the new_feature branch? He should be in it already.

I had a similar question to the OP regarding this part of the teachers notes :

This time, I'm going to use a shortcut that creates and checks out the new branch all in one step.
We don't run git branch at all.
Instead, we add the -b command-line option to the git checkout command: git checkout -b add-letters
This will cause the branch we specify to be created before checking it out.

In other words, using git branch -b to create a new branch versus just using git branch is purely for convenience, in that you can execute a single command to be checked out on the new branch rather than any fundamental difference between the two commands.

1 Answer

Aakash Srivastav
seal-mask
.a{fill-rule:evenodd;}techdegree
Aakash Srivastav
Full Stack JavaScript Techdegree Student 11,638 Points

The git checkoutcommand lets you navigate between the branches created by git branch. Whilegit branchcommand can be used to create a new branch. Thegit branch` command's primary functions are to create, list, rename and delete branches. To operate further on the resulting branches the command is commonly used with other commands like git checkout.