Yuri S. Cherkasov Yuri S. Cherkasov - 2 months ago 22
Git Question

Git: error src refspec does not match any; different behavior on Windows and Linux

On Windows my usual workflow is:

git init
git pull https://<repo_address> "branch_name"
git commit --all -m"message"
git push https://<repo_address> "branch_name"


After performing all branch tests, merging to master, let's say

git checkout master


or just cd to another dir and merge

git pull https://<repo_address> "branch_name"


On Windows it works perfectly. However, when I ported my app to Linux, surprisingly I got stuck on pushing my branch

git init
git pull https://<repo_address> "branch_name"
git commit --all -m"message"
git push https://<repo_address> "branch_name"


Getting well-known error

error: src refspec branch_name does not match any.
error: failed to push some refs to 'https://<repo_address>'


I found a couple of solutions but nothing suits me. Not sure that the cause is OS, maybe just different versions or whatever.

On Linux git version 2.1.4

Answer

I would recommend doing either a clone (which pulls down the repo and all branches), or if you want to get just a single branch, you can just add the remote and then fetch the branch. Cloning is probably the easiest but if you only want the single branch you can do the following steps.

git init
git remote add -t <branch_name> -f origin https://<repo_address>
git checkout <branch_name>

Then you can commit and push.

Comments