threads / discuss / 23556

git pull behavior changed?

Subject: git pull behavior changed?

## tl;dr

22 messages between Apr 21, 2010 and Apr 22, 2010.

replies: 21people: 8as markdown or json

Aghiles· Apr 21, 2010, 21:13 UTC · lore
Hello,

I used to 'git pull' in a branch and it was working without any questions asked. But now, if I do the following:

git checkout -b test git pull

I get a warning telling me that "You asked me to pull without telling me which branch ...". I would expect that my new local branch behaves the same way as the master branch.

I am using 1.7.0.3
  -- aghiles
Sverre Rabbelier· Apr 21, 2010, 21:22 UTC · re: Aghiles · lore

Re: git pull behavior changed?

Heya,
On Wed, Apr 21, 2010 at 23:13, Aghiles <aghilesk@gmail.com> wrote:
> git checkout -b test

When you do this you're telling git "I want a new branch from where I am right now". If you want to be able to pull in a similar way to how master works, use the '--track' option.

-- 
Cheers,

Sverre Rabbelier
Aghiles· Apr 21, 2010, 21:34 UTC · re: Sverre Rabbelier · lore

Re: git pull behavior changed?

Show 5 quoted lines
>
> When you do this you're telling git "I want a new branch from where I
> am right now". If you want to be able to pull in a similar way to how
> master works, use the '--track' option.
>

This means that when pulling I will be pulling from the remote ? That is what I want to achieve. I just want all my branches to pull from the same remote (as my master branch does).

Thank you for your help.
  -- aghiles
Aghiles· Apr 21, 2010, 21:55 UTC · re: Sverre Rabbelier · lore

Re: git pull behavior changed?

> When you do this you're telling git "I want a new branch from where I
> am right now". If you want to be able to pull in a similar way to how
> master works, use the '--track' option.
Actually, the '--track' option is exactly what I don't want ! :) It tells me:
"Branch test set up to track local branch refs/heads/master."

Without the '--track' option it seems to work as expected: when I pull it downloads data form the remote but then stops before merging. This used to work! What happened ? :(

  -- aghiles
Sverre Rabbelier· Apr 21, 2010, 21:59 UTC · re: Aghiles · lore

Re: git pull behavior changed?

Heya,
On Wed, Apr 21, 2010 at 23:55, Aghiles <aghilesk@gmail.com> wrote:
> Without the '--track' option it seems to work as expected: when I pull
> it downloads data form the remote but then stops before merging.
> This used to work! What happened ? :(

See the --track documentation, you need to tell it to track upstream instead of master.

-- 
Cheers,

Sverre Rabbelier
Matthieu Moy· Apr 21, 2010, 21:59 UTC · re: Aghiles · lore

Re: git pull behavior changed?

Aghiles <aghilesk@gmail.com> writes:
Show 6 quoted lines
>> When you do this you're telling git "I want a new branch from where I
>> am right now". If you want to be able to pull in a similar way to how
>> master works, use the '--track' option.
>
> Actually, the '--track' option is exactly what I don't want ! :) It
> tells me:
Read the doc. It is what you want, but you mis-use it.
-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/
Aghiles· Apr 21, 2010, 22:04 UTC · re: Matthieu Moy · lore

Re: git pull behavior changed?

Show 9 quoted lines
>
>>> When you do this you're telling git "I want a new branch from where I
>>> am right now". If you want to be able to pull in a similar way to how
>>> master works, use the '--track' option.
>>
>> Actually, the '--track' option is exactly what I don't want ! :) It
>> tells me:
>
> Read the doc. It is what you want, but you mis-use it.
I will read the doc, thank you for the advice.

'When creating a new branch, set up configuration to mark the start-point branch as "upstream" from the new branch.'

So no, that's not what I want.
Using :
  git branch test
  git checkout test
  git pull origin HEAD
Is what I want and it works. BUT, I used to need only 'git pull'
Again, the behavior changed since I last used this. No one cares?
  -- aghiles
Matthieu Moy· Apr 21, 2010, 22:23 UTC · re: Aghiles · lore

Re: git pull behavior changed?

Aghiles <aghilesk@gmail.com> writes:
> Again, the behavior changed since I last used this. No one cares?

The behavior of Git did not change. The content of your configuration file or the branch you are on did. The way to put the right content in your configuration file is --track.

When you create a branch, you say what the starting point of your branch is, and if you say --track, Git remembers it and uses it for pull next time. The simplest is to start your branch based on remotes/<name>/<branchname>, which is where your probably want to pull from.

Otherwise, --set-upstream may help. But neither will help untill you RTFM.

-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/
Aghiles· Apr 21, 2010, 22:41 UTC · re: Matthieu Moy · lore

Re: git pull behavior changed?

> Otherwise, --set-upstream may help. But neither will help untill you
> RTFM.

Matthieu, I spend my days reading the git manual and also the source code, which is not normal IMHO. I always look for examples but in the case of 'git branch' there is not many that are really useful!

I suggest to add this as an example since it is probably the most common case (one would expect that a new branch simply mimics the characteristics of the starting branch, no ?)

  git branch --track small_fixes origin
And it does what I want.

Again, the behavior changed: just upgraded to 1.7.0.3, before then I was doing branches like this:

  git checkout -b small_fixes
  git pull
>From my point of view, that was neat!

The --track and <start-point>=origin seemed to be implied. I find that this is a better better default (OR 'git pull' was defaulting to 'git pull origin HEAD').

As of now, 'git branch x' seem to be of little use without more configuration.
  -- aghiles
Jeff King· Apr 22, 2010, 00:01 UTC · re: Aghiles · lore

Re: git pull behavior changed?

On Wed, Apr 21, 2010 at 06:41:16PM -0400, Aghiles wrote:
Show 5 quoted lines
> Again, the behavior changed: just upgraded to 1.7.0.3, before then I was
> doing branches like this:
> 
>   git checkout -b small_fixes
>   git pull

What was the old version of git? A long time ago (maybe 1.5.x or earlier?) we used to default unconfigured pulls differently.

-Peff
Aghiles· Apr 22, 2010, 00:13 UTC · re: Jeff King · lore

Re: git pull behavior changed?

On Wed, Apr 21, 2010, Jeff King wrote:
> What was the old version of git? A long time ago (maybe 1.5.x or
> earlier?) we used to default unconfigured pulls differently.

I don't have the information handy but it was most probably pre-1.5. I don't know if my 'branching habits' are common, but I found that the old behavior to be more natural with the way we work (creating branches for quick parallel work).

If the current behavior is here to stay, I would humbly suggest to mention the 'git checkout -b x origin' syntax in the manual (and 'git branch --track x origin').

On a positive note, I would like to say that there is a good progress regarding the messages git prints to guide the user. That is helpful.

  -- aghiles
Jeff King· Apr 22, 2010, 00:41 UTC · re: Aghiles · lore

Re: git pull behavior changed?

On Wed, Apr 21, 2010 at 08:13:48PM -0400, Aghiles wrote:
> I don't have the information handy but it was most probably pre-1.5.
> I don't know if my 'branching habits' are common, but I found that
> the old behavior to be more natural with the way we work (creating
> branches for quick parallel work).

OK, then the behavior did change for you. But you are probably about 3 years too late to complain and try to get it changed. :)

> If the current behavior is here to stay, I would humbly suggest to
> mention the 'git checkout -b x origin' syntax in the manual (and
> 'git branch --track x origin').

It is in the checkout manual, but I think the subtlety that you missed is that "--track" is going to care about whether you start your branch from your local "master" or the remote "master". Even if they're at the same commit, you are interested conceptually in basing your work on what the remote is doing. Maybe we could talk about this in the definition of <start-point>, I guess.

You may also be interested to know that "git checkout foo" these days when you have no "foo" branch will do the equivalent of "git checkout -b --track foo origin/foo", which would also do what you want.

-Peff
Aghiles· Apr 22, 2010, 01:27 UTC · re: Jeff King · lore

Re: git pull behavior changed?

> OK, then the behavior did change for you. But you are probably about 3
> years too late to complain and try to get it changed. :)

Dammit. :) But really no biggie. I just entered panic mode because I thought something got borked in my favorite tool, which is not the case obviously.

> You may also be interested to know that "git checkout foo" these days
> when you have no "foo" branch will do the equivalent of "git checkout -b
> --track foo origin/foo", which would also do what you want.

Wouldn't that create/track a remote 'foo' branch ? I have no remote branches but only local ones so I am always tracking origin/master.

  -- aghiles
Jeff King· Apr 22, 2010, 02:10 UTC · re: Aghiles · lore

Re: git pull behavior changed?

On Wed, Apr 21, 2010 at 09:27:31PM -0400, Aghiles wrote:
Show 6 quoted lines
> > You may also be interested to know that "git checkout foo" these days
> > when you have no "foo" branch will do the equivalent of "git checkout -b
> > --track foo origin/foo", which would also do what you want.
> 
> Wouldn't that create/track a remote 'foo' branch ? I have no remote branches
> but only local ones so I am always tracking origin/master.

Yes, it would, so I guess it doesn't help you. You should do "git checkout -b foo origin/master", then.

-Peff
Randal L. Schwartz· Apr 21, 2010, 23:27 UTC · re: Aghiles · lore

Re: git pull behavior changed?

>>>>> "Aghiles" == Aghiles  <aghilesk@gmail.com> writes:

Aghiles> Using : Aghiles> git branch test Aghiles> git checkout test Aghiles> git pull origin HEAD

I do this:
    git checkout -b test origin/test
    ...
    git pull
And it seems to work.  It even announces that my test is tracking origin/test.
-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion
Aghiles· Apr 21, 2010, 23:57 UTC · re: Randal L. Schwartz · lore

Re: git pull behavior changed?

On Wed, Apr 21, 2010, Randal L. Schwartz  wrote:
Show 5 quoted lines
>    git checkout -b test origin/test
>    ...
>    git pull
>
> And it seems to work.  It even announces that my test is tracking origin/test.

Yes that syntax works too (although I use origin/master since I am tracking the main branch and not the remote "test" branch). Thank you very much.

The message announcing the tracked branch is a nice touch.
  -- aghiles
Petr Baudis· Apr 22, 2010, 08:10 UTC · re: Aghiles · lore

Re: git pull behavior changed?

On Wed, Apr 21, 2010 at 07:57:17PM -0400, Aghiles wrote:
Show 9 quoted lines
> On Wed, Apr 21, 2010, Randal L. Schwartz  wrote:
> >    git checkout -b test origin/test
> >    ...
> >    git pull
> >
> > And it seems to work.  It even announces that my test is tracking origin/test.
> 
> Yes that syntax works too (although I use origin/master since I am tracking
> the main branch and not the remote "test" branch). Thank you very much.

So, do I understand it right that there is still no canonical syntax to check out local branch tracking a remote one of the same name, without spelling out the branch name twice?

-- 
				Petr "Pasky" Baudis
http://pasky.or.cz/ | "Ars longa, vita brevis." -- Hippocrates
Junio C Hamano· Apr 22, 2010, 08:16 UTC · re: Petr Baudis · lore

Re: git pull behavior changed?

Petr Baudis <pasky@suse.cz> writes:
Show 7 quoted lines
> On Wed, Apr 21, 2010 at 07:57:17PM -0400, Aghiles wrote:
>> On Wed, Apr 21, 2010, Randal L. Schwartz  wrote:
>> >    git checkout -b test origin/test
> ...
> So, do I understand it right that there is still no canonical syntax to
> check out local branch tracking a remote one of the same name, without
> spelling out the branch name twice?
Only if you don't count Dscho's DWIM.
    $ git checkout tr/word-diff
    Branch tr/word-diff set up to track remote branch tr/word-diff from origin.
    Switched to a new branch 'tr/word-diff'
Petr Baudis· Apr 22, 2010, 11:49 UTC · re: Junio C Hamano · lore

Creating tracked branches

On Thu, Apr 22, 2010 at 01:16:10AM -0700, Junio C Hamano wrote:
Show 15 quoted lines
> Petr Baudis <pasky@suse.cz> writes:
> 
> > On Wed, Apr 21, 2010 at 07:57:17PM -0400, Aghiles wrote:
> >> On Wed, Apr 21, 2010, Randal L. Schwartz  wrote:
> >> >    git checkout -b test origin/test
> > ...
> > So, do I understand it right that there is still no canonical syntax to
> > check out local branch tracking a remote one of the same name, without
> > spelling out the branch name twice?
> 
> Only if you don't count Dscho's DWIM.
> 
>     $ git checkout tr/word-diff
>     Branch tr/word-diff set up to track remote branch tr/word-diff from origin.
>     Switched to a new branch 'tr/word-diff'
Ugh. Right, so _this_ is what kept me from ever learning the proper way:
  (i) If you do `checkout B`, it will track remote branch B if it exists.
  (ii) If you do `checkout -b B`, it will never auto-track anything.
  (iii) If you do `git checkout -t -b B`, it will auto-track your current
_local_ branch.

This keeps getting me really confused, I hope I will remember it now for good, but I have seen others having trouble with this as well. I don't have immediate ideas that would do less harm than good to fix this up...

perhaps except changing (iii) to auto-track the remote branch B if it exists and require tracked branch name if it doesn't - the current default seems pretty much useless to me for usual cases. (I can imagine a scenario where it would be useful, but not a common scenario where this would be useful default.)

P.S.: The "--track without -b implies branch creation" sentence in git-checkout(1) seems to be plain wrong?

-- 
				Petr "Pasky" Baudis
http://pasky.or.cz/ | "Ars longa, vita brevis." -- Hippocrates
Andreas Schwab· Apr 22, 2010, 13:47 UTC · re: Petr Baudis · lore

Re: Creating tracked branches

Petr Baudis <pasky@suse.cz> writes:
> P.S.: The "--track without -b implies branch creation" sentence in
> git-checkout(1) seems to be plain wrong?
$ git branch -r
  origin/HEAD -> origin/master
  origin/html
  origin/maint
  origin/man
  origin/master
  origin/next
  origin/pu
  origin/todo
$ git checkout -t origin/maint
Branch maint set up to track remote branch maint from origin.
Switched to a new branch 'maint'
Andreas.
-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."
Petr Baudis· Apr 22, 2010, 14:17 UTC · re: Andreas Schwab · lore

Re: Creating tracked branches

On Thu, Apr 22, 2010 at 03:47:11PM +0200, Andreas Schwab wrote:
Show 8 quoted lines
> Petr Baudis <pasky@suse.cz> writes:
> 
> > P.S.: The "--track without -b implies branch creation" sentence in
> > git-checkout(1) seems to be plain wrong?
> 
> $ git checkout -t origin/maint
> Branch maint set up to track remote branch maint from origin.
> Switched to a new branch 'maint'

Ah! I have not read all the gory details carefully enough. Wonderful, so this would be:

Show 7 quoted lines
>   (i) If you do `checkout B`, it will track remote branch B if it
> exists.
> 
>   (ii) If you do `checkout -b B`, it will never auto-track anything.
> 
>   (iii) If you do `git checkout -t -b B`, it will auto-track your
> current _local_ branch.
  (iv) If you do `git checkout -t R`, it will track branch R, deriving
local branch name B from it.
-- 
				Petr "Pasky" Baudis
http://pasky.or.cz/ | "Ars longa, vita brevis." -- Hippocrates
Aghiles· Apr 22, 2010, 21:13 UTC · re: Junio C Hamano · lore

Re: git pull behavior changed?

Show 7 quoted lines
>
> Only if you don't count Dscho's DWIM.
>
>    $ git checkout tr/word-diff
>    Branch tr/word-diff set up to track remote branch tr/word-diff from origin.
>    Switched to a new branch 'tr/word-diff'
>
Dscho's DWIM ? I hope I don't have to learn that to use git efficiently! :)
  -- aghiles

← back to recent threads