git push on branch src refspec does not match any

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?


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)


如果要使用与本地分支名称不同的名称推送到远程分支,请使用冒号分隔本地名称和远程名称:

git push origin local-name:remote-name
链接地址: http://www.djcxy.com/p/48964.html

上一篇: 部署到Herokuy时出现Postgres端口错误

下一篇: git推分支src refspec不匹配任何