[Solved] warning refname 'origin/master' is ambiguous - Github
While working with git you may face an error that says,
Refname is ambiguous
This error may occur for various reasons like matching of tag and branch name or matching a branch name with the SHA1 prefix of a commit. In this article, we are going to show you some easy steps to solve the problem.
Solution 1:
The error mostly occurred when a branch name and a tag name matches one another. For example, you have a branch named master also a tag named master. At that time, when you try to perform git operations it will show refname ambiguous error. In that case, you can rename your tag name by
$ git tag new_tag old_tag $ git tag -d old_tag $ git push origin new_tag :old_tag
Using the colon in the push command, the tag is removed from the remote repository. If you don't do this, when you pull, Git will generate the old tag on your system. Finally, make certain that the deleted tag is removed by coworkers. Instruct them to run the command:
$ git pull --prune --tags
Solution 2:
If you know that a ref-name is a branch or a tag you can prefix the id with either heads/ or tags/. So this works:
$ git checkout heads/[ref-name]
Given [ref-name] Git searches a list of locations. This is the list according to the git help revisions page:
- If $GIT_DIR/[ref-name] exists, that is what you mean (this is usually useful only for HEAD, FETCH_HEAD, ORIG_HEAD, MERGE_HEAD, and CHERRY_PICK_HEAD)
- otherwise, refs/[ref-name] if it exists
- otherwise, refs/tags/[ref-name] if it exists
- otherwise, refs/heads/[ref-name] if it exists;
- otherwise, refs/remotes/[ref-name] if it exists
- otherwise, refs/remotes/[ref-name]/HEAD if it exists
refs/heads/tags/[ref-name]
Solution 3:
Sometimes, you may get this error if a branch name matches the SHA1 prefix of a commit. For example, your branch name is 1601 and SHA1 prefix of a commit starts with 1601 at that time you may face the error. Making a ref name that is also a four-or-more-long hex string is likely to generate this type of ambiguity because object id prefixes of at least four digits are valid methods of referencing objects. So, try to avoid it. If you want to use a number, include a type marker, like bugfix/1601 or something.
Thank you for reading the article. Hope any of the above solutions will solve your problem.