Subject: Re: error: src refspec refs/heads/master matches more than one.

From: Duy Nguyen <[email-masked]>
Date: Sat, 15 Feb 2014 15:53:55 +0700

On Fri, Feb 14, 2014 at 08:32:07AM -0800, Junio C Hamano wrote:
> Duy Nguyen <[email-masked]> writes:
> 
> > On Fri, Feb 14, 2014 at 7:45 PM, Andreas Schwab <[email-masked]> wrote:
> >> Josef Wolf <[email-masked]> writes:
> >>
> >>> Notice the refs/heads _within_ refs/heads!
> >>>
> >>> Now I wonder how I managed to get into this situation and what's the best way
> >>> to recover?
> >>
> >> Probably you did something like "git branch refs/heads/master".  You can
> >> remove it again with "git branch -d refs/heads/master".
> >
> > As a porcelain, "git branch" should prevent (or at least warn) users
> > from creating such refs, I think.
> 
> "warn", possibly, but I do not see a reason to *prevent*.
> 
>  A. You are not allowed to call your branch with a string that begins with
>     'refs/heads/'.
>  B. Why?
>  A. Because it will confuse you.
>  B. I know what I am doing.
>  A. ???

Prevent is a strong word. I meant we only do it if they force
it. Something like this..

-- 8< --
diff --git a/branch.c b/branch.c
index 723a36b..3f0540f 100644
--- a/branch.c
+++ b/branch.c
@@ -251,6 +251,11 @@ void create_branch(const char *head,
 			forcing = 1;
 	}
 
+	if (!force && dwim_ref(name, strlen(name), sha1, &real_ref))
+		die(_("creating ref refs/heads/%s makes %s ambiguous.\n"
+		      "Use -f to create it anyway."),
+		    name, name);
+
 	real_ref = NULL;
 	if (get_sha1(start_name, sha1)) {
 		if (explicit_tracking) {
-- 8< --