threads / discuss / 20731

Confused about push/pull of a branch

Subject: Confused about push/pull of a branch

## tl;dr

5 messages between Aug 25, 2009 and Aug 25, 2009.

replies: 4people: 2as markdown or json

Fritz Anderson· Aug 25, 2009, 17:40 UTC · lore

I can't get a second machine to pull in a branch that's in my remote repository. I'm confused.

The remote is a bare repository on machine_1.
In my working copy on machine_1:
machine_1$ git branch
   master
   search-controller
   use-tiles
* webservices
# The following should not be necessary, as gitk already
# identifies a remotes/origin/webservices, but just to be sporting:
machine_1$ git push origin webservices
Everything up-to-date

Branch webservices was created after the working copy on machine_2 was cloned.

In my working copy on machine_2:
machine_2$ git pull
Password:
# Progress messages, no protests.
machine_2$ git checkout webservices
error: pathspec 'webservices' did not match any file(s) known to git.
machine_2$ git branch
* master
machine_2$

git-config shows the two repository URLs are identical, net of machine_2 having to specify a user name and host. The machine_2 .git/ config shows a section for [branch "master"], but not for webservices. Is that the problem? What's the approved way of adding [branch "webservices"], and what do I put into it?

I've obviously forgotten something. Or never understood something (there's a lot in Git not to understand). How do I get the webservices branch onto machine_2, so I can check it out?

	— F
Fritz Anderson· Aug 25, 2009, 17:58 UTC · re: Fritz Anderson · lore

Re: Confused about push/pull of a branch

On Aug 25, 2009, at 12:40 PM, Fritz Anderson wrote:
> I can't get a second machine to pull in a branch that's in my remote  
> repository. I'm confused.
And just from half-wittedly fooling around, I tried:
machine_2$ git pull origin webservices
Password:
 From fritza@fritzanderson.uchicago.edu:/Users/fritza/scientia/scientia
  * branch            webservices -> FETCH_HEAD
Updating 3c86901..6b09f9f
Fast forward
  Calendar/Classes/CalendarWebController.m |    2 ++
# etc.
  dirserver/lib/ldaputils.rb               |   15 +++++----------
  6 files changed, 34 insertions(+), 17 deletions(-)
machine_2$ sudo /usr/local/bin/git branch
* master
machine_2$

This seems to mean that master on machine_2 is now congruent to webservices on machine_1. That's not what I meant. Is there a way to undo this? git-pull origin-master doesn't seem to do anything.

	— F
Fritz Anderson· Aug 25, 2009, 18:00 UTC · re: Fritz Anderson · lore

Re: Confused about push/pull of a branch

On Aug 25, 2009, at 12:58 PM, Fritz Anderson wrote:
> This seems to mean that master on machine_2 is now congruent to  
> webservices on machine_1. That's not what I meant. Is there a way to  
> undo this? git-pull origin-master doesn't seem to do anything.
Sigh. "git pull origin master". Sorry.
	— F
Jeff King· Aug 25, 2009, 18:32 UTC · re: Fritz Anderson · lore

Re: Confused about push/pull of a branch

On Tue, Aug 25, 2009 at 12:58:25PM -0500, Fritz Anderson wrote:
Show 6 quoted lines
> >I can't get a second machine to pull in a branch that's in my
> >remote repository. I'm confused.
> 
> And just from half-wittedly fooling around, I tried:
> 
> machine_2$ git pull origin webservices

That will merge the 'webservices' branch from your origin with your current branch (which looks like 'master' in this case).

Remember that "pull" in git is really just "fetch" and "merge". What you want is "fetch" and "create a new local branch":

  $ git fetch
  $ git checkout -b webservices origin/webservices

except that the "fetch" step has probably already been done as a side-effect of the pull you did earlier.

> This seems to mean that master on machine_2 is now congruent to
> webservices on machine_1. That's not what I meant. Is there a way to
> undo this? git-pull origin-master doesn't seem to do anything.

Sort of. It contains all the changes of 'master' _and_ all the changes of 'webservices'. However in this case there were no changes in 'master' that were not already in 'webservices', so we were able to "fast forward" to where webservices is. If the two branches had diverged at all, you would have had a merge (potentially with conflicts).

To undo it, you probably want:
  $ git checkout master ;# make sure we are on master branch
  $ git reset --hard origin/master ;# go back to where remote master is
-Peff
Jeff King· Aug 25, 2009, 18:27 UTC · re: Fritz Anderson · lore

Re: Confused about push/pull of a branch

On Tue, Aug 25, 2009 at 12:40:47PM -0500, Fritz Anderson wrote:
Show 13 quoted lines
> Branch webservices was created after the working copy on machine_2
> was cloned.
> 
> In my working copy on machine_2:
> 
> machine_2$ git pull
> Password:
> # Progress messages, no protests.
> machine_2$ git checkout webservices
> error: pathspec 'webservices' did not match any file(s) known to git.
> machine_2$ git branch
> * master
> machine_2$

Try "git branch -a", which will list remote branches. You likely have a remote tracking branch "origin/webservices". You can check that out to examine it, or if you want to start working on it locally, try "git checkout -b webservices origin/webservices".

> git-config shows the two repository URLs are identical, net of
> machine_2 having to specify a user name and host. The machine_2 .git/
> config shows a section for [branch "master"], but not for
> webservices. Is that the problem? What's the approved way of adding
> [branch "webservices"], and what do I put into it?

The branch.webservices config is not necessary for a branch; it just says "by the way, when you do a pull without arguments and we are on this branch, here is where to pull from". Doing the "checkout -b" above will create such a config section on recent versions of git.

> I've obviously forgotten something. Or never understood something
> (there's a lot in Git not to understand). How do I get the
> webservices branch onto machine_2, so I can check it out?

The branching model in git is a little different than other systems. Just because the remote has a branch does not mean _you_ have a branch. When you fetch from them (or pull, which does a fetch behind the scenes), you will have a "remote tracking branch" which is your local copy of where their remote branches are. You still need to create your own local branch if you want to do work on it (and bear in mind your branch doesn't need the same name or to be related in any long term way; you are merely using their remote branch as a starting point for your branch).

-Peff

← back to recent threads