error: src refspec master does not match any
Solution 1
From git branch
it appears that somehow your local branch name is "origin".
You can rename the branch with -mv
flag, like this:
git branch -mv origin master
After this git branch
should show master
:-)
Just to make sure the name is indeed the only thing that went astray, you can run git log
and look at the last few commits - and compare them to the last few commits on bitbucket website.
Solution 2
This should help you
git init
git add .
git commit -m 'Initial Commit'
git push -u origin master
Solution 3
i have same problem, to solve it, follow these steps
git init
git add .
git commit -m 'message'
git push -u origin master
after this, if you still having that error, follow these steps again
git add .
git commit -m 'message'
git push -u origin master
that worked for me and Hope it will help anyone
Solution 4
Try to do :
git push origin HEAD:master
Solution 5
Try following command:
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'.

special0ne
Updated on July 05, 2022Comments
-
special0ne 6 months
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: Followed this solution
// adding the file I created $ git add . $ git commit -m 'initial commit' $ git push origin master error: src refspec master does not match any.
When doing:
$ git push origin HEAD:master b40ffdf..a0d1423 HEAD -> master // looks promising // adding a remote $ git remote add devstage -f <another git> $ git merge devstage/master -s recursive -X ours $ git push -u devstage master error: src refspec master does not match any.
More information:
$ git branch * origin $ git show-ref refs/heads/origin refs/remotes/devstage/master refs/remotes/origin/HEAD refs/remotes/origin/devstage refs/remotes/origin/master refs/remotes/origin/origin
So I am definitely missing refs/heads/master but dont know how to create it.
Thanks
-
special0ne almost 9 yearsTo start working I did: >git clone https://<User>@bitbucket.org/<RepoPath> Which created the following .git/config [core] repositoryformatversion = 0 filemode = false bare = false logallrefupdates = true symlinks = false ignorecase = true hideDotFiles = dotGitOnly [remote "origin"] url = https://<User>@bitbucket.org/<RepoPath> fetch = +refs/heads/*:refs/remotes/origin/* [branch "origin"] remote = origin merge = refs/heads/origin Am I doing something wrong?
-
apprenticeDev almost 9 yearshmm, just doing
git clone repo_address
should be perfectly good. For some bizarre reason the local branch got named "origin" (evident frombranch [origin]
section of git/config). Why did it do it? I don't know. Did you try my suggestion of renaming the branch? If it doesn't work, you can also change your [branch] section of gitconfig manually to read as follows:[branch 'master'] remote = origin merge = refs/heads/master
-
skwidbreth over 6 yearsAwesome! I was running into this problem, too - it was because I had cloned a repo with a non-master branch checked out (which was what I wanted), but forgot to rename the branch
master
in the new repo. -
Kyung Hwan Min over 6 yearsafter adding git add ., git push -u origin master works
-
pixel about 6 yearsand how is initiating a local git repo without adding it to remote going to help anyone??? You are missing the main step git remote add ....
-
GhostRider about 5 yearsWorked like a charm
-
Yunnosch about 5 yearsPlease copy the textual information from the picture directly to your answer. Then please explain how this is actually an answer to the question. I have the impression that it isn't one. It at least lacks an explanation of why it is not possible and how to actually solve the problem.
-
r3wt over 4 yearsthis works when you're on a new repo and have never committed.
-
arslan ahmed mir over 4 yearsYup ! I faced this problem with my very first repository
-
bibliophilsagar over 4 yearssimple and elegant. Here take one from me soldier.
-
Vansh Bhardwaj about 2 yearsIt worked, but if you have to push to your own repo, what it does is, first reacted a pull request on my own repo and then I had to merge my own pull request.
-
emppeak almost 2 yearsI came here after I got an error while pushing to heroku, and found this answer useful after running
git push heroku main
Because at this time of posting github main branch is namedmain
frommaster
. I hope it helps someone in future, probably me. -
Junior Mayhé almost 2 yearsA brand new repo created in github was setup as main. After cloning we can see "main" instead of "master". So push in this case must be
git push -u origin main