git push on branch src refspec does not match any
Solution 1
You may explicitly specify to which remote branch you're pushing:
git push origin myBranch:existing_remote_branch
Actually it seems that you perform many excessive steps and generally the workflow is much simpler. Also it's worth to check Configure a local branch for push to specific branch
Update:
Assuming git is relatively modern, I would go as follows:
git clone "$myurl" "$myfolder"
cd "$myfolder"
git checkout "$mybranch"
git remote set-head origin "$mybranch"
... add and commit your changes here ...
git push origin "$mybranch"
I'd like to ask why you created two different git repositories, one in "$myfolder" and another in "$myfolder/<project_name>" ? Is that expected behavior? (I can imagine cases when it may be useful, but they're "corner-cases", at best)
Solution 2
If you want to push to a remote branch with a different name than your local branch, separate the local and remote names with a colon:
git push origin local-name:remote-name
John
Updated on June 07, 2022Comments
-
John almost 2 years
I would like to clone a branch, make a change and push into the same branch.
I'm doing this:
mkdir myfolder cd myfolder git init git clone "myurl" -b "mybranch" git remote add origin "myurl" edit "myfile.txt" git add "myfile.txt" git commit -m "my comment" git push origin "mybranch"
but I got this error:
error: src refspec "mybranch" does not match any error: failed to push some refs to "myurl"
what should I do?
-
John about 10 yearsso, also if I clone just a branch, it seem in my local repository I am in master. Should I do
git push origin master:mybranch
, right? what is the simpler workflow? -
John about 10 yearshi, well that's a good point, thanks a lot for direct me in the right way. I'll have a look and let you know. Thanks a lot for now.
-
Elydasian almost 3 yearsPlease provide an explanation to your code, so that the next user knows exactly why did this solution worked for you.
-
Elydasian almost 3 yearsYes it is, keep it up :)