Link to home
Start Free TrialLog in
Avatar of Bruce Gust
Bruce GustFlag for United States of America

asked on

How Do I Retrieve the Contents of a Remote Branch

I'm working with a co-worker who created a new branch on a project that we're both working on. I want to retrieve the code that he put on that branch and put it on my computer.

I'm going through what I can find online and the command would seem to be:

git fetch origin <branch name>

"<branch name> is the new branch that my coworker just created. So if the new branch he just created is "new-master," then all I need to do is:

git fetch origin new-master

Right?

It's not working. What am I missing?
Avatar of Juan Ocasio
Juan Ocasio
Flag of United States of America image

Are you using a centralized repository?  If so, try doing a git fetch, and then a git checkout origin/new-master
Avatar of Bruce Gust

ASKER

Here's what I did, Juan:

git fetch origin new-master

"new-master" is the branch I'm trying to download.

You ask about a centralized repository. Not sure how to answer that other than saying I'm trying to retrieve code from Github.
ok.  So first do a git fetch.  Then do a git checkout origin/new-master
OK, Juan, real quick...

When I do a Git pull, I'm grabbing the master branch on the remote repository and merging that into my master branch on my local box, correct?

I do that to bring my master along with every other branch that I'm tracking up to speed with what is the "newest and best" code that's out there. I'm basing all of that one the tutorial I'm working through and this page: https://stackoverflow.com/questions/292357/what-is-the-difference-between-git-pull-and-git-fetch

Correct?

Here's what I found about fetching:

Getting new branches: At the initial point of a clone you will have all the branches. However, if other developers add branches and push them to the remote there needs to be a way to 'know' about those branches and their names in order to be able to pull them down locally. This is done via a git fetchwhich will get all new and changed branches into the locally repository using the tracking branches (e.g. origin/). Once fetched, one can git branch --remote to list the tracking branches and git checkout [branch] to actually switch to any given one. (https://www.quora.com/Whats-the-difference-between-git-pulland-git-fetch)

So, it looks as though "fetching" is bringing down all of the branches that I may or may not be aware of and gives me access to them on my local box.

Perfect!

But what's happening to my local master branch at that point? When I do a "fetch," I'm thinking there are some possible changes that have been made to the origin/master branch. If they're not being merged like what would happen in the context of a git pull, are those changes just lingering out there that will never be acknowledged unless I do a git merge, or what's happening to those?

Thanks!
ASKER CERTIFIED SOLUTION
Avatar of Juan Ocasio
Juan Ocasio
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Got it!

Thanks!
Excellent, Juan!
You're welcome.  Hope this was helpful.