threads / discuss / 6363

1.5.0.rc1.gb60d: fetch in another branch works strangely

Subject: 1.5.0.rc1.gb60d: fetch in another branch works strangely

## tl;dr

3 messages between Jan 13, 2007 and Jan 13, 2007.

replies: 2people: 3as markdown or json

Horst H. von Brand· Jan 13, 2007, 21:06 UTC · lore

I created a new branch in the kernel to carry a not yet official patch, to keep this up to date I do:

   $ git fetch git://git2.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git
   $ git pull . origin

The kernel repository is quite old, so it has the old-fashoned setup. I see:

  $ less .git/refs/heads/bz-7795 
  d132ed980aee1bdcc6fa02b91da95a357902eb3c
  $ less .git/refs/heads/origin  
  d39c9400ae0d60aaaf534b1ad860a9bc1413d8af
And this last ref doesn't change when fetching.

Strangely, each time I fetch it gets 7 new objects (I haven't pulled, I do that once I'm sure I've got all). As I tend to doubt that we are /that/ syncronized with Linus, something fishy is going on here...

First noticed this with 1.5.0.rc1.g4494.
-- 
Dr. Horst H. von Brand                   User #22616 counter.li.org
Departamento de Informatica                    Fono: +56 32 2654431
Universidad Tecnica Federico Santa Maria             +56 32 2654239
Casilla 110-V, Valparaiso, Chile               Fax:  +56 32 2797513
Shawn O. Pearce· Jan 13, 2007, 21:14 UTC · re: Horst H. von Brand · lore

Re: 1.5.0.rc1.gb60d: fetch in another branch works strangely

"Horst H. von Brand" <vonbrand@inf.utfsm.cl> wrote:
> I created a new branch in the kernel to carry a not yet official patch, to
> keep this up to date I do:
> 
>    $ git fetch git://git2.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git

That's only writing into FETCH_HEAD whatever branch is marked as HEAD in Linus' repository. No local refs are being updated.

>    $ git pull . origin
So this won't merge in the changes fetched above.

Why not setup that URL as a remote (git remote add linus ....) Then you can do:

  $ git fetch linus
  $ git merge linus/master
or 
  $ git fetch linus
  $ git pull . linus/master
or 
  $ git pull linus master
-- 
Shawn.
Junio C Hamano· Jan 13, 2007, 21:46 UTC · re: Horst H. von Brand · lore

Re: 1.5.0.rc1.gb60d: fetch in another branch works strangely

"Horst H. von Brand" <vonbrand@inf.utfsm.cl> writes:
> I created a new branch in the kernel to carry a not yet official patch, to
> keep this up to date I do:
>
>    $ git fetch git://git2.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git

If you use longhand without colon-refspec (src:dst), then the fetch result will be in temporary ref, FETCH_HEAD. (google, or gmane search for a message on "temporary ref" and "FETCH_HEAD" by Linus for gory details). So next fetch will keep re-fetching the same thing (this has been how "fetch" was designed to work from day one and there is nothing new).

>    $ git pull . origin

You do not have origin tracking branch (well, you do -have- one, but by doing the longhand without colon-refspec, you choose not to keep it up-to-date), so that would try to merge an ancient copy you obtained probably when you cloned to create the repository.

You either can do:
 (1) Ad-hoc promiscuous pull without using tracking branch
     $ git pull git://git.kernel.org/...../linux-2.6.git
     This is good for one-shot pulling from random place when
     you notice somebody you usually do not interact with has
     something interesting.  I do not think you would want to do
     that with Linus.
 (2) Use remote shorthand, define and maintain tracking branch(es).
     In the traditional configuration,
     you would have .git/remotes/origin that says something
     like:
	URL: git://git.kernel.org/...../torvalds/linux-2.6.git
	Pull: refs/heads/master:refs/heads/origin
     With the newer configuration, the moral equivalent is found
     in your .git/config file and would look like something like
     this:
	[remote "origin"]
        	url = git://git.kernel.org/...../linux-2.6.git/
		fetch = +refs/heads/*:refs/remotes/origin/*
	[branch "master"]
        	merge = refs/heads/master
     In either way, you can update the tracking branch with:
     $ git fetch origin ;# or just "git fetch"
     With this, since you -do- have and -maintain- the tracking
     branch, you can do after this "git fetch":
     $ git merge origin
     to merge in what you have fetched.

← back to recent threads