I clone my repository with:
git clone ssh://xxxxx/xx.git
But after I change some files and add
and commit
them,
This will also happen if you have a typo in the branch name you're trying to push.
Missing or skipping git add .
or git commit
may cause this error:
git push -u origin master
Username for 'https://github.com': yourusername
Password for 'https://yourusername@github.com':
error: src refspec master does not match any.
error: failed to push some refs to 'https://github.com/yourusername/foobar.git'
To fix it, reinitialize and follow the proper sequence:
git init
git add .
git commit -m 'message'
git *create remote
git push -u origin master
Make sure you've added first, and then commit/ push:
Like:
git init
git add .
git commit -m "message"
git remote add origin "github.com/your_repo.git"
git push -u origin master
In the scenario where you check out the code from an external repository (GitHub), and want to import it in personal / internal system, this command really shines:
git push --all origin
This pushes all local branches to the remote, without checking refs and without insisting on commits.
For me I had to make sure the public key is properly configured on the server (appended in ~/.ssh/authorized_keys) and in GitHub/Bitbucket (added to my SSH keys on GitHub or Bitbucket) - they need to match.
Then:
git add --all :/
git commit -am 'message'
git push -u origin master
It worked for me in the end.
If you get this error while working in detached HEAD mode, you can do this:
git push origin HEAD:remote-branch-name
See also: Making a Git push from a detached head
If you are on a different local branch than the remote branch, you can do this:
git push origin local-branch-name:remote-branch-name