1

I have accidentally created a local branch name that is the same as a name on the remote repository. When I pulled the recent remote updates, I started getting "warning: refname 'the-name" is ambiguous." and I do not seem to be able to get to the updated branch of the remote.

How do I get them to both display with their reference numbers?

How do I rename only my local one?

(git branch -move old new) did not work!

(git tag -d name) worked! 

Thanks to everyone.

  • 1
    That's really only possible with branch and *tag* names (or, a branch name and an abbreviated commit hash—e.g., a branch named `cafe` might be mistaken for the 4-character short name of a commit with hash `cafedad007...`), but it's definitely possible. – torek Oct 21 '20 at 04:55
  • Please provide more detail info, what's the exact name of branch? The screenshot of your command and result. From my experience, the local branch name and the remote branch name should always keep the same, and it will not have ambiguous problem. Maybe you can also provide the result of `git branch -a` – Chuck Lu Oct 21 '20 at 05:24
  • You can also check this answer https://stackoverflow.com/questions/13073062/git-warning-refname-master-is-ambiguous/13083619#13083619 – Chuck Lu Oct 21 '20 at 07:45
  • 1
    You can try `git for-each-ref | grep $branchname` to print the ambiguous refs. – ElpieKay Oct 21 '20 at 08:10
  • @ChuckLu: No screenshots of text please! You can't (easily) index those for a search. The actually issued commands and the ensuing errors *are* necessary though! – Ulrich Eckhardt Oct 21 '20 at 17:28

2 Answers2

2

Use git branch -m to rename your branch:

git branch -m oldname newname

Edit: per question-edit, it seems that you had a branch named X (for some X) and a tag also named X (for some X). In this particular case, some operations resolve the name to the branch name, and some to the tag name.

Deleting one of the names works, of course. But you can also disambiguate the names. A branch or tag name is a bit like someone's given name. If you have two guys named Bruce, you can refer to them as Bruce Arthur Robertson and Bruce Leonard Sadler, and now everyone knows which Bruce you mean—and similarly, you can refer to refs/head/X to refer to branch X, and refs/tags/X to refer to tag X. You can leave out the refs/ part, using heads/X and tags/X, as well.

Since tag names are usually intended as global (shared across all clones, and everyone's v1.2 will refer to the exact same commit) while branch names are usually intended as local (your debug2 commit is probably different from Fred's debug2 commit), it's generally wise to name tags carefully, and then never change or delete them; branch names are more ephemeral and easier to change and delete. But these aren't hard-and-fast rules, so do whatever is appropriate for your situation.

torek
  • 448,244
  • 59
  • 642
  • 775
0

You need two commands in order to rename a branch.

  • git checkout -b <newname> <oldname> With this, you can create a new branch that is a copy of the old one.

  • git branch -D <oldname> That command can be used in order to delete the old branch.

dan1st
  • 12,568
  • 8
  • 34
  • 67