Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Development Tools Git Basics Branches Branching Out

What is branch in git? and what are its uses?

a

2 Answers

Basically, you have your master branch and you don't want to mess anything up on that branch. However, you need to implement a new feature that works with the codebase on the master branch. A branch will allow to make a "copy" while not affecting the original branch (master in this case).

So, to get around this problem you can a branch (We'll call it 'new_feature') that is a copy of the master branch and add your new feature code the the new_feature branch. Once you have finished implementing the new feature you merge the new_feature branch with master and BOOM, done.

I will include a link to the gitflow workflow. This really helped me understand branching and why you should use it.

Nicholas Arcuri
Nicholas Arcuri
11,311 Points

Think of it like a tree.. The master is the trunk, of which you can branch off from. You start a new branch off of the original master so that you can make changes to the project without affecting the original master branch. Whoever else is working on the project can continue with the master branch as well. Then, when you finish your changes you can merge back with the master branch and your changes will be present, along with whatever else was changed in the meantime.