9

Hi I want to push something to specific remote branch

I make local areas by

git clone https://~~~.Something
cd https://~~~.Something

and I can access specific branch using

git checkout origin/[branch]

I want to commit something to my specific branch origin/[branch] But when I am trying to push something using by

git push origin [branch]

I got this error

error: src refspec [branch] does not match any.
error: failed to push some refs to 'https://github.com/kkammo/yonseitree.git'

I tried to solve this problem but I can't find any solution... so plz help me T.T

Zoe
  • 27,060
  • 21
  • 118
  • 148
kwony
  • 109
  • 1
  • 1
  • 5
  • Did you not get a big warning message about `detached HEAD` when you did your `git checkout origin/[branch]` – Andrew C Nov 02 '14 at 21:04

2 Answers2

44

A replicated question here, src refspec master does not match any when pushing commits in git

Try git show-ref to see what refs do you have. Is there refs/heads/[branch]?

You can try git push origin HEAD:[branch] as more local-reference-independent solution.

It works for me.

Community
  • 1
  • 1
Luna Kong
  • 3,065
  • 25
  • 20
  • "git show-ref" wasn't showing my branch, but after I performed "git push origin HEAD:[branch]", it showed up on the next "git show-ref" - thank you Luna! – sellmaurer Feb 20 '17 at 01:46
  • 1
    Seems to do the trick, upvoted but could you add some explanation on why does it solve the issue? – TheMP Nov 06 '19 at 09:28
  • should be marked as solution. Also would be nice to have explanation – Izzy Rodriguez Dec 17 '19 at 20:52
  • I have the same error. The reason is that I did not commit anything to the local repo. After committing, everything's going well. – krave Jan 01 '21 at 13:24
1

Below is your now branch:

* dev master remotes/origin/master

The new branch dev is created from master and have been done some commits.

Use the command below to push this new branch:

git push -u origin --tags HEAD:dev

After that, we check again:

* dev master remotes/origin/dev remotes/origin/master

That's OK for me.

Max Xu
  • 2,403
  • 1
  • 15
  • 13