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 Branches and Merging Merging Merging Into Topic Branches

Jamie Reardon
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Jamie Reardon
Treehouse Project Reviewer

git checkout branch before merging?

In the video, the teach was checking out the two branches (master and testing) before merging the contents of the each with the command: git merge testing (for checked out master branch) and git merge master (for checked out testing branch).

So my question is, is this necessary to perform the checkouts before merging? Couldn't you also stay in a different checked out branch e.g. git checkout fix-nils and then run the command git merge master testing / git merge testing master to get the same desired results?

Thanks!

1 Answer

Hi Jamie

I believe this video is showing you how to merge two local branches.

In this case you do need to checkout the receiving branch to ensure the HEAD is pointing to the correct merge-receiving branch.

This is needed because a working copy is needed to compare against to fix any potential conflicts when git is trying to find a common base commit between the two branches.

The example you give will actually merge branches master and testing on top of the current branch. Making a 3-way merge (octopus merge)

 git merge master testing

There are short-hands that can however, fetch and rebase, but only for specific non-fast forward situations.