I have tried to follow the solutions suggested in this post but it didnt work and I am still getting: src refspec master does not match any.
Here is what I did: Fo
FWIW, ran into same error, but believe it came about due to the following sequence of events:
master
branch.dev
branch, which was defined as the default branch, in conjunction with permissions added to the master
branch preventing changes without a pull request.Then, when attempting to push changes from the local to the remote, received error "src refspec master does not match any", or when attempting to push to dev
, "src refspec dev does not match any".
Because changes were pending in the local clone, I did not want to blast it and refresh.
So, fixed the issue by renaming the local branch to dev
...
$ git branch -m dev
...followed by the normal push of git push origin dev
, which worked this time without throwing the aforementioned error.
git push origin HEAD:master
Git threw the below error when I tried simply git push
. So clearly this is because Git matches the local and remote branch while pushing commits. This is the push.default
behavior, you can find out more details here.
fatal: The upstream branch of your current branch does not match
the name of your current branch. To push to the upstream branch
on the remote, use
git push origin HEAD:<Branch_Name>
To push to the branch of the same name on the remote, use
git push origin <Branch_Name>
To choose either option permanently, see push.default in 'git help config'.
For a new repository, the method works for me:
Remote the files related with git
rm -rf .git
Do the commit again
git add . && git commit -m "your commit"
Add the git URL and try to push again
git remote add origin <your git URL>
And then try to push again
git push -u origin master -f
Success!
Since it's a new repository, so it doesn't matter for me to remove the git and add it again.
This error can typically occur when you have a typo in the branch name.
For example you're on the branch adminstration
and you want to invoke:
git push origin administration
.
Notice that you're on the branch without second i
letter: admin(i)stration
, that's why git prevents you from pushing to a different branch!
I had already committed the changes and added all the files, had the same origin as remote, still kept getting that error. My simple solution to this was just:
git push
This is happend to me once I forgot to add files. So I got the same error. All you need to do is add your files.
git add .
or the name of the files you want to add. you supposed to init first your repo with git init
.git commit -m 'Initial Commit'
.git push -u origin master