Refname is ambiguous

I can get this behavior by giving a branch a name that matches the SHA1 prefix of a commit.

$ git rev-list @ | egrep '^[0-9]{4}'
7802d6937673dbff4d26dc906c714a054c9e883e
81070af68e1b254c7f36eccb1261050a5a4a133a
7537dac08fd165845b6300f32c19a52fc7fa7299
$ git branch 7802
$ git branch 9999
$ git checkout 7802
warning: refname '7802' is ambiguous.
Switched to branch '7802'
$ git checkout 9999
Switched to branch '9999'
$

Since object id prefixes at least four digits long are legitimate ways of referring to objects, making a ref name that’s also a four-or-more-long hex string is likely to produce this kind of ambiguity. So, don’t do that. If you want to number something, include a type marker, like bugfix/1601 or something.

Leave a Comment