All of
 help / color / mirror / Atom feed
From: Jeff King <>
To: Bill Lear <>
Cc: Junio C Hamano <>,
Subject: Re: Git rescue mission
Date: Thu, 8 Feb 2007 18:24:04 -0500	[thread overview]
Message-ID: <> (raw)
In-Reply-To: <>

On Thu, Feb 08, 2007 at 09:27:32AM -0600, Bill Lear wrote:

> > - never build on a branch that appears on the RHS of ':'.
> This I don't quite understand.  So, if it is on the LHS, it is ok?
> But, if it is ALSO on the RHS it is not?

If it is on the LHS, it's talking about the branch in the _remote_ repo.

> So, this:
>       Pull: refs/heads/topic:refs/heads/topic
> really means don't don't work on a branch named topic in this
> repository?

It means to fetch the remote's branch "refs/heads/topic" and store the
current head in _your_ "refs/heads/topic" as a tracking branch, but only
if it's a fast-forward. Yes, I know it says "Pull:", but it's really
about fetching.

You can then merge the result of that fetch into your current branch. So
what you want is something like:

Pull: refs/heads/topics:refs/heads/remote-topic

which will use 'remote-topic' as a tracking branch, always updating it
at fetch time to reflect the remote's version of topic. You can then
merge remote-topic into your local topic branch by fetching+merging, or
by doing 'git-pull remote refs/heads/topic:refs/heads/remote-topic'.

> I assume by "build on" you mean "work, compile, check stuff in,
> etc."?.  Did you have something else in mind when you said "build on"?

I believe he means 'store commits in'. That is, the RHS of the refspec
should be used solely for tracking fetches from the remote. If you make
a commit on top of it (either directly, or by doing a merge), then the
fetch must either throw away your commits, or fail to fast-forward to
the remote's new position for that branch.

> I don't currently have any 'refs/remotes' of any sort, so I guess you
> mean that the new principle, using git clone --use-separate-remote
> will effect this.

Yes. It will basically give you a RHS of "refs/remotes/$REMOTE/$BRANCH"
to track a branch $BRANCH coming from $REMOTE (generally "origin"); it's
a more organized way of doing what I mentioned above (RHS of

> >(git-clone from 1.5.0 does not actually make remotes/origin file
> >in .git/ that has the above -- it creates the moral equivalent
> >in .git/config).
> So, using 1.4.4 series, or 1.5, the "sane" way to work in git
> is to use clone --use-separate-remotes.

Most people think so (though I think Junio actually still uses the
traditional layout, because he finds it more convenient). Note that in
1.5, --use-separate-remote is the default (the option is still
accepted, but has no effect; note also that the option is singular).

> I assume by this you mean that if I do the separate remote trick, I
> will not shoot myself by doing a 'git pull' while on my topic branch,
> as the setup will cause git to refuse to do it.

No, you will not shoot yourself because the fetch part of the pull will
store the remote's position of 'refs/heads/topic' at
'refs/remotes/origin/topic' instead of trying to overwrite the branch
you've been working on.

As an additional bonus, you can put this in your .git/config:

[branch "topic"]
remote = origin
merge = refs/heads/topic

which means "When I'm on my refs/heads/topic branch and I issue a
git-pull without any arguments, do a git-fetch on origin. Then, merge
what the remote end calls refs/heads/topic into my current branch."
Without this, git-pull in v1.4.* will attempt to merge the remote's
'master' branch. In v1.5, I believe it will refuse to make a merge.

> Ok, so if I am on master, I do this:
> [master] % git pull
> and this will fetch the remote master and merge it to my master, and
> fetch the remote topic and merge it to my local topic.
> While, if I am on my topic branch, if I do this:
> [topic] % git pull
> it sill fetches from the remote master and the remote topic, but will
> not merge at all.
> Could you verify if I have stated your position correctly?

That is correct. If you add the config I mentioned above, you can get
the "automatically merge from remote topic into my topic" behavior that
you get for master.

> If I am, this still seems bizarre.  I really just want a way to sync
> two repos that works consistently, and is invoked consistently, no
> matter what branch I am currently on.  And, again, by "sync", I just
> mean no cross-branch merging --- no "crossing of the streams".  Even
> if it were limited to syncing the current branch only, that would be
> ok, but this variable behavior seems rather odd and confusing.  In
> other words, I just want to type the equivalent of 'git sync' and have
> it work, and not have to give a branch name, or be in the "right
> place" for it to work as I expect.

Syncing repositories doesn't involve pulling. It just involves fetching.
So in either case, you can simply do a 'git-fetch origin'. In v1.5,
the repositories won't be exactly identical; your remote branches will
be stored in refs/remotes/origin instead of refs/heads.

However, your original setup is still broken for syncing. You are doing
local work on refs/heads/topic, but you also are claiming you want to
store the sync of the remote in refs/heads/topic. You obviously can't do

> Thus, I don't want to have to think "oh, I'm on my topic branch, and
> if I really want to sync from my remote repo, I need to get on my
> master branch".  It seems that the only difference in the "insane" way

Maybe I don't understand what you mean by sync here, but I don't see the
mental leap. Whenever you fetch, from whatever branch, using the
'origin' remote, it will update all tracking branches in your local
repository. You can then selectively do merges to any local branches
you're working on. You _can't_ do an operation that is "for every local
branch I have, merge the matching remote branch into my local branch".
And I don't think you'd want to: a merge may or may not be a trivial
thing, since it might have conflicts.

The workflows I suspect you want are:

1. I'm working on my topic, and somebody else is working on topic. Pull
   their work from the remote 'origin':

     git checkout topic
     hack hack hack
     git commit
     git pull origin

  Using separate remotes, you'll get a copy of the remote topic branch
  in your refs/remotes/origin/topic. If you have the config magic I
  mentioned above, it will automagically pull from his topic branch. If
  not, it will either pull from his master (v1.4) or complain (v1.5).

2. I'm working on my topic, and now I want to pull from the remote
   master to do some testing.

     git checkout topic
     hack hack hack
     git commit
     git fetch origin
     git merge origin/master

   This will only work in v1.5.  Using separate remotes, the
   'origin/master' branch refers to the 'refs/remotes/origin/master'
   tracking branch. You could do it in v1.4 like this (without using a
   tracking branch at all):

     git pull origin master

3. I'm interested in what's happening on the topic branch, but I don't
   care about making local commits. I just want to build it.

     git checkout origin/topic
     build build build

   It assumes you are tracking using separate remotes (hence the
   origin/topic branch). This will _only_ work in v1.5, since you're
   not allowed to checkout any non-branch refs in v1.4 (including tags
   or remote tracking branches). The moral equivalent in v1.4 using
   separate remotes is:

     git checkout -b topic origin/topic
     build build build

   which leaves you with your own local 'topic' branch, which you can
   then merge into if you want.

Hope that makes sense.


  parent reply	other threads:[~2007-02-08 23:24 UTC|newest]

Thread overview: 51+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-02-08  0:18 Git rescue mission Bill Lear
2007-02-08  0:22 ` Johannes Schindelin
2007-02-08  0:24   ` Bill Lear
2007-02-08  0:25     ` Johannes Schindelin
2007-02-08  0:34       ` Bill Lear
2007-02-08  0:48 ` Junio C Hamano
2007-02-08  4:28   ` Alexander Litvinov
2007-02-09  0:53     ` Junio C Hamano
2007-02-09  3:32       ` Alexander Litvinov
2007-02-08 15:27   ` Bill Lear
2007-02-08 15:56     ` Jakub Narebski
2007-02-08 23:24     ` Jeff King [this message]
2007-02-08 23:32       ` Bill Lear
2007-02-08 17:27 ` Linus Torvalds
2007-02-08 20:12   ` Kalle Pokki
2007-02-08 21:23     ` Linus Torvalds
2007-02-08 22:03       ` Kalle Pokki
2007-02-08 22:10         ` Shawn O. Pearce
2007-02-09  1:48           ` Theodore Tso
2007-02-09  1:58             ` Shawn O. Pearce
2007-02-09  2:01             ` Jakub Narebski
2007-02-10 16:05             ` Theodore Ts'o
2007-02-10 16:05               ` [PATCH] Print a sane error message if an alias expands to an invalid git command Theodore Ts'o
2007-02-10 16:05                 ` [PATCH] Allow aliases to expand to shell commands Theodore Ts'o
2007-02-10 18:04                   ` Linus Torvalds
2007-02-10 18:13                   ` Theodore Tso
2007-02-10 20:34                     ` Johannes Schindelin
2007-02-11  0:13                       ` Theodore Tso
2007-02-11 16:03                         ` Johannes Schindelin
2007-02-11 16:21                           ` Theodore Tso
2007-02-11 16:36                             ` Johannes Schindelin
2007-02-11 21:44                             ` Junio C Hamano
2007-02-11 22:03                               ` Johannes Schindelin
2007-02-12  3:56                               ` Theodore Tso
2007-02-12  6:53                                 ` Shawn O. Pearce
2007-02-10 16:50                 ` [PATCH] Print a sane error message if an alias expands to an invalid git command Junio C Hamano
2007-02-09 19:21           ` Git rescue mission Kalle Pokki
2007-02-08 21:57   ` Bill Lear
2007-02-08 22:13     ` Linus Torvalds
2007-02-08 22:33       ` Bill Lear
2007-02-08 23:25       ` Bill Lear
2007-02-08 23:33         ` Shawn O. Pearce
2007-02-08 23:40           ` Bill Lear
2007-02-08 23:50             ` Shawn O. Pearce
2007-02-09  0:03             ` Jakub Narebski
2007-02-09  0:17             ` Linus Torvalds
2007-02-09  8:58             ` Michael S. Tsirkin
2007-02-08 23:38         ` Jakub Narebski
2007-02-08 23:46         ` Linus Torvalds
2007-02-09  4:38       ` Junio C Hamano
2007-02-08 22:29     ` Jakub Narebski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \ \ \ \ \ \

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.