警告: refname‘ master’是不明确的

我看到一些人在这里问同样的问题,但似乎他们的建议都不适用于我。我得到了这个标题中的警告,但是我没有任何名为“主人”的标签。这是 git branch -a的结果:

* master
remotes/origin/HEAD -> origin/master
remotes/origin/master

你知道会出什么问题吗?我现在使用 git 只有几个月的时间,所以我最担心的是这种模糊性可能会在未来给回购带来麻烦。

67338 次浏览

As detailed in "Git: refname 'master' is ambiguous", that means that, beside heads/master, you have another master in one of the following namespace within the git repo:

refs/<refname>
refs/tags/<refname>
refs/heads/<refname>
refs/remotes/<refname>
refs/remotes/<refname>/HEAD

Or even ./<refname>, as mentioned in Magnus's answer.

For me I tracked down the source of this warning to much earlier when I incorrectly issued an "update-ref" command. If you forget to specify the full refs/heads/mybranchname path in the first arg, then a file .git/mybranchname gets created, which later leads to this warning when you try to switch to that branch.

It is solved by simply deleting the .git/mybranchname, eg:

rm .git/master

And for reference, the correct form for the update-ref command is:

git update-ref refs/heads/mybranchname mytargetbranch

Don't forget the "refs/heads" part!

Also, my most common use-case for update-ref is simply manually moving a branch to point to another commit, which I've found a simpler syntax to do:

git branch -f myBranchToMove destinationBranchOrHash

This syntax is easier for me because it doesn't require that error-prone refs/heads path qualifier.

git fetch --prune


git pull origin branch-name

should fix your problem.

I had a similar problem (not master) when I created a branch with the same name as a tag.

This helped me remove the tag https://stackoverflow.com/a/5480292/150953

git push --delete origin tagname

For future reference, I had the same issue and what ended up to work for me was the solution described here. Basically, when you get Git: warning: refname 'xxx' is ambiguous warning, you can use: git show-ref xxx to check the references to xxx branch and validate which ones are having conflict.

In my scenario, it was a tag named xxx and branch name with the same name. The tag had been made by mistake and was removed from server so all I needed to do was to update my local tag to match the server: git fetch -p -P. This command is explained in details here

Check your .git/config file. You may run into this problem if you have more than one remote repo configured with the same:

fetch = +refs/heads/*:refs/remotes/origin/*.

The other remote server should have a different name, eg.:

fetch = +refs/heads/*:refs/remotes/another_repo/*