# howto handle name clashes

6 messages from 2012-03-23 to 2012-03-24. Participants: Sven Strickroth, Jeff King, Junio C Hamano.
Thread: https://gitlist.dev/t/30035

## Sven Strickroth, 2012-03-23 13:06

Subject: howto handle name clashes
Message-ID: <4F6C7539.3080607@tu-clausthal.de>
URL: https://gitlist.dev/e/4F6C7539.3080607%40tu-clausthal.de

```
Hi,

how to handle name clashes for branches and tags? Is there anything I
can add to the refspec to make the name unique?

E.g.
- for merging "git merge --no-ff refs/branches/test" works, but
generates a not so nice default merge message. ("merged  commit
refs/branches/test" instead of "merged branch test")
- how to drop a remote tag/branch ("git push origin :test" does not work)

-- 
Best regards,
 Sven Strickroth
 ClamAV, a GPL anti-virus toolkit   http://www.clamav.net
 PGP key id F5A9D4C4 @ any key-server

```

## Jeff King, 2012-03-23 17:12

Subject: Re: howto handle name clashes
Message-ID: <20120323171219.GB12881@sigill.intra.peff.net>
URL: https://gitlist.dev/e/20120323171219.GB12881%40sigill.intra.peff.net
In-Reply-To: <4F6C7539.3080607@tu-clausthal.de>

```
On Fri, Mar 23, 2012 at 02:06:01PM +0100, Sven Strickroth wrote:

> how to handle name clashes for branches and tags? Is there anything I
> can add to the refspec to make the name unique?

You can always use a more fully-qualified name to disambiguate (e.g.,
"tags/foo", or "refs/tags/foo").

> - for merging "git merge --no-ff refs/branches/test" works, but
> generates a not so nice default merge message. ("merged  commit
> refs/branches/test" instead of "merged branch test")

Did you mean "refs/heads/test"?

I would have thought we would full-qualify the refname first, and then
use that to determine the message. Doing a simple test, it looks like
"git merge foo" gets you "Merge branch 'foo'", but "git merge heads/foo"
will get you "Merge branch 'heads/foo'". We should be able to do better
in the latter case.

> - how to drop a remote tag/branch ("git push origin :test" does not work)

Does "git push origin :heads/foo" (or :tags/foo) not work?

-Peff

```

## Sven Strickroth, 2012-03-23 17:43

Subject: Re: howto handle name clashes
Message-ID: <4F6CB649.8080006@tu-clausthal.de>
URL: https://gitlist.dev/e/4F6CB649.8080006%40tu-clausthal.de
In-Reply-To: <20120323171219.GB12881@sigill.intra.peff.net>

```
Am 23.03.2012 18:12 schrieb Jeff King:
>> - for merging "git merge --no-ff refs/branches/test" works, but
>> generates a not so nice default merge message. ("merged  commit
>> refs/branches/test" instead of "merged branch test")
> 
> Did you mean "refs/heads/test"?

yes. Your example was the correct one. Thanks for spotting my problem.

>> - how to drop a remote tag/branch ("git push origin :test" does not work)
> 
> Does "git push origin :heads/foo" (or :tags/foo) not work?

seems to work. Thanks.

Really problematic is checkout:
"git checkout heads/foo" creates a detached HEAD (is this intended).
However, "git checkout heads/foo -B foo" can be used.

Is there a git command to find out if a name is ambiguous?
"git rev-parse foo" outputs "warning: refname 'test' is ambiguous.", but
the return code is zero.

-- 
Best regards,
 Sven Strickroth
 ClamAV, a GPL anti-virus toolkit   http://www.clamav.net
 PGP key id F5A9D4C4 @ any key-server

```

## Junio C Hamano, 2012-03-23 18:25

Subject: Re: howto handle name clashes
Message-ID: <7vlimrtbrg.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vlimrtbrg.fsf%40alter.siamese.dyndns.org
In-Reply-To: <4F6C7539.3080607@tu-clausthal.de>

```
Sven Strickroth <sven.strickroth@tu-clausthal.de> writes:

> how to handle name clashes for branches and tags? Is there anything I
> can add to the refspec to make the name unique?
>
> E.g.
> - for merging "git merge --no-ff refs/branches/test" works, but
> generates a not so nice default merge message. ("merged  commit
> refs/branches/test" instead of "merged branch test")

That's the price you pay for naming different things the same and having
to disambiguate it.

> - how to drop a remote tag/branch ("git push origin :test" does not work)

"git push origin :refs/tags/test"

It is sad that some people teach new people shorthand without telling them
that what they are teaching are merely shorthand and cause confusion like
this.

```

## Jeff King, 2012-03-23 18:29

Subject: Re: howto handle name clashes
Message-ID: <20120323182941.GA14236@sigill.intra.peff.net>
URL: https://gitlist.dev/e/20120323182941.GA14236%40sigill.intra.peff.net
In-Reply-To: <4F6CB649.8080006@tu-clausthal.de>

```
On Fri, Mar 23, 2012 at 06:43:37PM +0100, Sven Strickroth wrote:

> Really problematic is checkout:
> "git checkout heads/foo" creates a detached HEAD (is this intended).
> However, "git checkout heads/foo -B foo" can be used.

Checkout is unlike regular ref lookup in that it prefers branches to
other forms (because it is fundamentally a branch operation). So "git
checkout foo" should always choose "refs/heads/foo". We do still seem to
give the ambiguity warning, though, which seems like overkill.

I think that generally people would want to get rid of ambiguous refs as
soon as they notice them, as they are a recipe for disaster. So the
warning being annoying has not been considered a huge problem.

> Is there a git command to find out if a name is ambiguous?
> "git rev-parse foo" outputs "warning: refname 'test' is ambiguous.", but
> the return code is zero.

I think you could do:

  case "$(git show-ref --tags --heads $name | wc -l)" in
  0) echo "$name does not exist" ;;
  1) echo "$name is unambiguous" ;;
  *) echo "$name is ambiguous" ;;
  esac

You could also get a list of all ambiguous refs like this:

  git for-each-ref --format='%(refname:short)' refs/heads refs/tags |
  egrep '^(heads|tags)'

The ":short" modifier will shorten names unambiguously, so it ends up
leaving the "heads" and "tags" in for ambiguous names.

-Peff

```

## Sven Strickroth, 2012-03-24 00:19

Subject: Re: howto handle name clashes
Message-ID: <4F6D132F.6020504@tu-clausthal.de>
URL: https://gitlist.dev/e/4F6D132F.6020504%40tu-clausthal.de
In-Reply-To: <20120323171219.GB12881@sigill.intra.peff.net>

```
Am 23.03.2012 18:12 schrieb Jeff King:
>> - how to drop a remote tag/branch ("git push origin :test" does not
>> work)
>
> Does "git push origin :heads/foo" (or :tags/foo) not work?

well, ":heads/foo" does not work. Imagine I want to drop a remote branch
which is ambiguous (e.g. a tag with same name exists) on the repository:

"git push origin :food"

gives me: "error: dst refspec food matches more than one."

However, deleting the remote tag (:tags/foo) works with your suggestion.

"git push origin :refs/remotes/origin/foo" showed success (and warning
"remote: warning: Allowing deletion of corrupt ref."), but did not work.

-- 
Best regards,
 Sven Strickroth
 ClamAV, a GPL anti-virus toolkit   http://www.clamav.net
 PGP key id F5A9D4C4 @ any key-server

```
