error: src refspec master does not match any

390,384

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'.
Share:
390,384
special0ne
Author by

special0ne

Updated on July 05, 2022

Comments

  • special0ne
    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
    special0ne almost 9 years
    To 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
    apprenticeDev almost 9 years
    hmm, just doing git clone repo_address should be perfectly good. For some bizarre reason the local branch got named "origin" (evident from branch [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
    skwidbreth over 6 years
    Awesome! 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
    Kyung Hwan Min over 6 years
    after adding git add ., git push -u origin master works
  • pixel
    pixel about 6 years
    and 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
    GhostRider about 5 years
    Worked like a charm
  • Yunnosch
    Yunnosch about 5 years
    Please 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
    r3wt over 4 years
    this works when you're on a new repo and have never committed.
  • arslan ahmed mir
    arslan ahmed mir over 4 years
    Yup ! I faced this problem with my very first repository
  • bibliophilsagar
    bibliophilsagar over 4 years
    simple and elegant. Here take one from me soldier.
  • Vansh Bhardwaj
    Vansh Bhardwaj about 2 years
    It 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
    emppeak almost 2 years
    I 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 named main from master. I hope it helps someone in future, probably me.
  • Junior Mayhé
    Junior Mayhé almost 2 years
    A 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