git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Elegant subdirectory checkout of remote-tracking branch?

From
W. Trevor King <wking@tremily.us>
Date
Mar 1, 2013, 15:22 UTC
Message-ID
<20130301152253.GA9312@odin.tremily.us>

I'm trying to figure out the most efficient way to keep an up to date `todo` branch checked out in Meta [1]. I've tried a few things like:

  $ git submodule add -b refs/remotes/origin/todo --reference ./ -- ./ Meta
and:
  $ git clone --single-branch --branch refs/remotes/origin/todo ./ Meta

These fail because I can't use a remote tracking branch as a source for the clone. It should be possible to do:

  $ git clone --reference . --single-branch --branch todo git://git.kernel.org/pub/scm/git/git.git Meta

but that will require (I think) network access during a fetch. Since I'm already fetching `origin` from the superproject, I don't want to have to refetch them for the submodule (or whatever Meta ends up being). Here's what I think happens with a submodule fetch:

1. Query the remote URL to dereference its current `todo` branch.
2. Check if we have that object in our local object share (which
   we should, due to --reference and a recent superproject
   fetch).
3. Fetch any missing objects from the remote URL.
I want to replace step 1 with:
1b. Query the superproject to dereference its current
    `origin/todo` branch.
and step 3 with:
3b. Access objects from the superproject directly (as with
    --reference / --shared).
Do I need to setup something like:
  [remote "origin"]
    url = ../.git
    fetch = +refs/remotes/origin/todo:refs/remotes/origin/todo
by hand, or is there an easier way?

I can, of course, clone a local `todo` branch if I've set one up in my superproject. However, then I'd have to update-ref that branch to sync with origin/todo after every fetch (that updates origin/todo). This could be handled with a `git fetch` wrapper, but… yuck :p.

Any suggestions for an elegant solution would be appreciated :). Once we figure something out, I can write it up and stick it in howto/maintain-git.txt.

Cheers, Trevor

[1]: http://article.gmane.org/gmane.comp.version-control.git/144748
-- 
This email may be signed or encrypted with GnuPG (http://www.gnupg.org).
For more information, see http://en.wikipedia.org/wiki/Pretty_Good_Privacy
Next: Junio C Hamano
Message 1 of 3 in “Elegant subdirectory checkout of remote-tracking branch?”
  1. W. Trevor KingMar 1, 2013
  2. Junio C HamanoMar 1, 2013
  3. Jeff KingMar 2, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.