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

The order of multiple remote.xx.fetch is significant for some operations

From
Jiang Xin <worldhello.net@gmail.com>
Date
Jul 6, 2012, 02:06 UTC
Message-ID
<CANYiYbEH_qxj40SiVeYgLT_fYiRSh7O+wwSim1u=dBDfoZMiFA@mail.gmail.com>

Someone asked me how to remove obsolete topgit feature branches from the remote topgit controlled git repo. I found we can not run "git fetch --prune" directly to delete stale remote branches from local, because of the wrong order of multiple "remote.XX.fetch" config variable.

For example, config variables for remote "origin":
    [remote "origin"]
          fetch = +refs/heads/*:refs/remotes/origin/*
          url = git@github.com:ossxp-com/topgit.git
          fetch = +refs/top-bases/*:refs/remotes/origin/top-bases/*

When running "git fetch --prune", will check all local refs, and delete stale remote branches from local if their conterparts do not exist in remote repo. But in this case, all remote branches under "refs/remotes/origin/top-bases/" namespace will be deleted, even their remote conterparts "refs/top-bases/*" still exist in remote repo.

How does this happen? e.g. a local ref: "refs/remotes/origin/top-bases/t/featureX"

 * First make a reverse look up according to the remote.origin.fetch
   config variables;
 * The first remote.origin.fetch matches, and this local ref is mapped
   as "refs/heads/top-bases/t/featureX";
 * The remote repo does not have ref "refs/heads/top-bases/t/featureX",
   (it should be "refs/top-bases/t/featureX"), then this local refs is
   deleted as a stale remote branch.
 * While if we change the order of remote.origin.fetch config variables,
   The result is different. This local ref will map to
   "refs/top-bases/t/featureX", and won't be deleted.

So, it's not a bug of git, but a flaw of user generated config variables. The hacks for Topgit are simple, see:

 * https://github.com/ossxp-com/topgit/blob/master/debian/patches/t/delete-remote-branch.diff
 * https://github.com/ossxp-com/topgit/blob/master/debian/patches/t/prune-stale-remote-branch.diff

-- Jiang Xin

Message 1 of 1 in “The order of multiple remote.xx.fetch is significant for some operations”
  1. Jiang XinJul 6, 2012

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.