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

Re: [BUG] fetching all remote branches results in failed multiple updates

From
SZEDER Gábor <szeder.dev@gmail.com>
Date
Mar 7, 2019, 23:40 UTC
Message-ID
<20190307234015.GD28939@szeder.dev>
In-Reply-To
<20190307214447.GA4909@chabuduo>
On Thu, Mar 07, 2019 at 09:44:47PM +0000, Alexander Huynh wrote:
Show 31 quoted lines
> Hello all,
> 
> When running the latest release of git, I receive an error when attempting to
> fetch all remote branches from a repo:
> 
>     fatal: multiple updates for ref 'refs/remotes/origin/maint' not allowed
> 
> The specific ref that it fails on changes depending on the repository, but the
> end result is the repo isn't cloned.
> 
> The specific configuration that causes this bug is the `remote.origin.fetch`
> option, specifically:
> 
>     [remote "origin"]
>     	fetch = +refs/heads/*:refs/remotes/origin/*
> 
> These settings are listed as an example in "CONFIGURED REMOTE-TRACKING
> BRANCHES" of git-fetch(1), as well as expanded upon in
> https://stackoverflow.com/a/40739835.
> 
> I'm running git version 2.21.0.
> 
> Full reproduction steps are below:
> 
>     [root@chabuduo ~]# useradd -m git-test -s /bin/bash
>     [root@chabuduo ~]# sudo --preserve-env=SSH_AUTH_SOCK -u git-test -i
>     [git-test@chabuduo ~]$ git --version
>     git version 2.21.0
>     [git-test@chabuduo ~]$ cat > ~/.gitconfig
>     [remote "origin"]
>     	fetch = +refs/heads/*:refs/remotes/origin/*
Why do you do this?

First, this is the default refspec configuration that clone will fetch and set up in the clone's config file anyway. You don't have to set it.

Second, setting repository-specific stuff like the default fetch refspec in the global configuration is not such a good idea.

So the simplest workaround is:
  rm ~/.gitconfig; git clone git@github.com:git/git.git
Show 11 quoted lines
>     [git-test@chabuduo ~]$ cat ~/.gitconfig
>     [remote "origin"]
>     	fetch = +refs/heads/*:refs/remotes/origin/*
>     [git-test@chabuduo ~]$ git clone git@github.com:git/git.git
>     Cloning into 'git'...
>     Warning: Permanently added the RSA host key for IP address '192.30.255.112' to the list of known hosts.
>     remote: Enumerating objects: 265113, done.
>     remote: Total 265113 (delta 0), reused 0 (delta 0), pack-reused 265113
>     Receiving objects: 100% (265113/265113), 113.20 MiB | 5.49 MiB/s, done.
>     Resolving deltas: 100% (196542/196542), done.
>     fatal: multiple updates for ref 'refs/remotes/origin/maint' not allowed

Anyway, this is a side-effect of 515be83382 (clone: respect additional configured fetch refspecs during initial fetch, 2018-11-14). Since then the same refspec comes up twice in remote->fetch, once from the configuration and once the explicitly added default refspec. And since 'git clone' doesn't run a fully-fledged 'git fetch' and has its own simple refs-to-refspec matching logic, it ends up trying to write each ref twice, once for each of the two refspecs, in a single ref transaction.

Previous: Alexander HuynhNext: Alexander Huynh
Message 2 of 6 in “[BUG] fetching all remote branches results in failed multiple updates”
  1. Alexander HuynhMar 7, 2019
  2. SZEDER GáborMar 7, 2019
  3. Alexander HuynhMar 8, 2019
  4. Junio C HamanoMar 8, 2019
  5. Alexander HuynhMar 13, 2019
  6. Alexander HuynhMar 14, 2019

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.