10

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?

2
  • It does appear that you did something weird when cloning. To clone correctly, use git clone [url] [destination path]. For more diagnostic help, post what you get when you run git config -l Mar 12, 2011 at 1:41
  • Thanks mark, I get: core.repositoryformatversion=0 core.filemode=true core.bare=false core.logallrefupdates=true core.ignorecase=true remote.master.fetch=+refs/heads/*:refs/remotes/master/* [email protected]:###/###.git branch.master.remote=master branch.master.merge=refs/heads/master
    – Andrew J
    Mar 12, 2011 at 1:55

3 Answers 3

12

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
6

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.

1
  • 1
    +1 for referencing the documentation where this is explained. I wish git didn't try refs/remotes/<name>/HEAD - it only creates confusion for people who aren't quite sure what remotes and branches are, with very little benefit for anyone who does understand the difference... Mar 12, 2011 at 9:10
0

In my case HEAD branch was ambiguous and solved by deleting local branch using

git branch -d HEAD

may need to push changes before not to lose changes

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.