Question

When I was working on merging couple of branches, i have accidentally created a branch instead of merging,

Example :

I was checking the list of branches available in the local and origin by typing git branch. But accidentally i have executed git branch origin/DEV66 (origin/DEV66 is the branch i need to merge with the branch test).

So I have the following problem when merging the branch test and origin/DEV66

warning: refname 'origin/DEV_66' is ambiguous.
warning: refname 'origin/DEV_66' is ambiguous.

When typing git branch it shows the following branches

GRNDEV_893
heads/origin/GRNDEV_893
remotes/origin/GRNDEV_893

How to resolve this ambiguity and is there is any different between the branches heads/origin/GRNDEV_893 and remotes/origin/GRNDEV_893.

Was it helpful?

Solution

Branches in heads/ are branches local to your repository, which you've created in this clone with git branch or git checkout -b. Branches in remotes/ are remote tracking branches, which are read-only copies of branches from other clones that are updated with you run a git fetch or a git pull.

When you have branches with the same name in both, you can disambiguate by including the heads/ or remotes/ prefix:

git checkout test
git merge remotes/origin/DEV_66

Since you created heads/origin/DEV_66 by mistake, you can delete it like so:

git branch -d heads/origin/DEV_66

OTHER TIPS

git branch -rv will show all branches including remote branches, and commit each branch is pointing to at the moment. You can further inspect each branch by viewing log:

git log BRANCHNAME

In case some branches are identical and you would like to delete them, you can do that using

git branch -d BRANCHNAME

How to resolve this ambiguity and is there is any different between the branches heads/origin/GRNDEV_893 and remotes/origin/GRNDEV_893.

Git 2.23 (Q2 2019) will improve the code to show args with potential typo that cannot be interpreted as a commit-ish.

See commit 2ed2e19, commit 8ed51b0 (14 May 2019) by Jeff King (peff).
(Merged by Junio C Hamano -- gitster -- in commit 8d32d25, 13 Jun 2019)

help_unknown_ref(): check for refname ambiguity

When the user asks to merge "foo" and we suggest "origin/foo" instead, we do so by simply chopping off "refs/remotes/" from the front of the suggested ref.

This is usually fine, but it's possible that the resulting name is ambiguous (e.g., you have "refs/heads/origin/foo", too).

Let's use shorten_unambiguous_ref() to do this the right way, which should usually yield the same "origin/foo", but "remotes/origin/foo" if necessary.

Note that in this situation there may be other options (e.g., we could suggest "heads/origin/foo" as well). I'll leave that up for debate; the focus here is just to avoid giving advice that does not actually do what we expect.


With Git 2.24, calling help_unknown_ref() exits the program.

See commit 80e3658 (29 Aug 2019) by René Scharfe (rscharfe).
(Merged by Junio C Hamano -- gitster -- in commit 8e111e4, 30 Sep 2019)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top