# "git push" says "src refspec XYZ matches more than one" even without explicit XYZ argument.

2 messages from 2016-10-28 to 2016-10-28. Participants: Kannan Goundan, Junio C Hamano.
Thread: https://gitlist.dev/t/44387

## Kannan Goundan, 2016-10-28 03:00

Subject: "git push" says "src refspec XYZ matches more than one" even without explicit XYZ argument.
Message-ID: <CAM7aVoUOxx6Fa+yG2JzQhoX-mE4Lgp9ejvwncx5bdL+1tuQQFg@mail.gmail.com>
URL: https://gitlist.dev/e/CAM7aVoUOxx6Fa%2ByG2JzQhoX-mE4Lgp9ejvwncx5bdL%2B1tuQQFg%40mail.gmail.com

```
1. My repo has a branch named 'v1' that is tracking 'origin/v1'.
2. My repo has a tag named 'v1'.
3. I have "push.default" set to "upstream".

I made a commit on branch 'v1' and tried doing a push:

    # git push
    error: src refspec v1 matches more than one.
    error: failed to push some refs to 'git@github.com:whatever/ns1-go.git'

If I rename the branch to 'v1-dev', then the push goes through.

I understand why the command "git push origin/v1 v1" is ambiguous.
But if I do a plain "git push", I thought Git would know to push my
current branch.

[Git version 2.10.1 from Homebrew on Mac OS 10.11.6.]

```

## Junio C Hamano, 2016-10-28 19:13

Subject: Re: "git push" says "src refspec XYZ matches more than one" even without explicit XYZ argument.
Message-ID: <xmqq1sz01e41.fsf@gitster.mtv.corp.google.com>
URL: https://gitlist.dev/e/xmqq1sz01e41.fsf%40gitster.mtv.corp.google.com
In-Reply-To: <CAM7aVoUOxx6Fa+yG2JzQhoX-mE4Lgp9ejvwncx5bdL+1tuQQFg@mail.gmail.com>

```
Kannan Goundan <kannan@cakoose.com> writes:

> 1. My repo has a branch named 'v1' that is tracking 'origin/v1'.
> 2. My repo has a tag named 'v1'.
> 3. I have "push.default" set to "upstream".
>
> I made a commit on branch 'v1' and tried doing a push:
>
>     # git push
>     error: src refspec v1 matches more than one.
>     error: failed to push some refs to 'git@github.com:whatever/ns1-go.git'
>
> If I rename the branch to 'v1-dev', then the push goes through.
>
> I understand why the command "git push origin/v1 v1" is ambiguous.
> But if I do a plain "git push", I thought Git would know to push my
> current branch.
>
> [Git version 2.10.1 from Homebrew on Mac OS 10.11.6.]

Thanks.  

You are right that the refspec Git internally create for this case
should not be v1:refs/heads/v1, which would notice that the source
side (e.g. "v1") is ambiguous.  Instead we should spell that out.

Perhaps something like this would fix it for you?

 builtin/push.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/builtin/push.c b/builtin/push.c
index 3bb9d6b7e6..02fd235742 100644
--- a/builtin/push.c
+++ b/builtin/push.c
@@ -194,7 +194,7 @@ static void setup_push_upstream(struct remote *remote, struct branch *branch,
 			die_push_simple(branch, remote);
 	}
 
-	strbuf_addf(&refspec, "%s:%s", branch->name, branch->merge[0]->src);
+	strbuf_addf(&refspec, "%s:%s", branch->refname, branch->merge[0]->src);
 	add_refspec(refspec.buf);
 }
 

```
