I have a public repository at github.com with 2 branches : master
and test
.
I created a new directory locally and did:
[ ] git clone [email protected]:{username}/{projectname}.git
Then I created a new branch named my_test
with
[ ] git branch my_test
and switched to it.
[ ] git checkout my_test
Then I merged it from my test
branch of my public repository with
[ ] git merge origin/test
and it resulted in a fast forward.
I made some changes and committed them. Then I tried to push the local my_test
branch to the public test
branch at github with
[ ] git push [email protected]:{username}/{projectname}.git test
but I got this error:
error: src refspec test does not match any. fatal: The remote end hung up unexpectedly error: failed to push some refs to '[email protected]:{username}/{projectname}.git
What am I doing wrong ?
A commit gets rejected and causes a failed to push some refs to error because the remote branch contains code that you do not have locally. What this means is that your local git repository is not compatible with the remote origin. Based on the above, your local machine is missing commits C and D.
To push a branch on remote, your branch needs to have the latest changes present in remote repository. If you get the failed to push error, first do git pull the branch to get the latest commits and then push it.
If git push origin master not working , all you need to do is edit that file with your favourite editor and change the URL = setting to your new location. Assuming the new repository is correctly set up and you have your URL right, you'll easily be able to push and pull to and from your new remote location.
Perhaps try:
git push [email protected]:{username}/{projectname}.git HEAD:test
The format of the last parameter on that command line is a refspec which is a source ref followed by a colon and then the destination ref. You can also use your local branch name (my_test
) instead of HEAD to be certain you're pushing the correct branch.
The documentation for git push
has more detail on this parameter.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With