Error on branch creation: “warning: refname 'master' is ambiguous.”

十年热恋 提交于 2019-12-05 23:41:06

问题


I've had simple project being managed in a Git repository. To date I haven't intentionally created any branches, but when I tried to create my first today using

$ git branch mybranch

I see this error:

warning: refname 'master' is ambiguous.
fatal: Ambiguous object name: 'master'.

Digging deeper:

$ git branch -a          
* master
remotes/master/HEAD -> master/master
remotes/master/master

Is this normal to see in Git? Have I cloned my repository incorrectly? What is the best way to resolve this problem?


回答1:


It seems it's ambiguous because your remote name and branch name are both master. You can try renaming the remote to the more conventional origin by running

git remote rename master origin



回答2:


The rules for how revision specifications are interpreted are given in gitrevisions(7) (referenced from git(1), among other bits of documentation).

In short, master matches two patterns when applied to the refs in your repository: a local branch (refs/heads/<name>) and the default remote-tracking branch of a remote (refs/remotes/<name>/HEAD).

These can be disambiguated by using heads/master for the local branch and master/HEAD (or master/master in your case) for the remote-tracking branch.

As Andrew Marshall mentions, you might want to rename your remote to avoid having to disambiguate in the first place.



来源:https://stackoverflow.com/questions/5280212/error-on-branch-creation-warning-refname-master-is-ambiguous

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!