Question

[Solved] error: src refspec master does not match any

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

Solution #1:

This should help you

git init
git add .
git commit -m 'Initial Commit'
git push -u origin master
Respondent: nithinreddy

Solution #2:

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.

Respondent: apprenticeDev

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
Respondent: Adrien Parrochia

Solution #5:

I was having the SAME ERROR AGAIN AND AGAIN.

I added files in local repository and Trying the command

“git push origin master”

Showed Same Error

ALL I WAS MISSING I DID NOT COMMIT .

” git commit -m ‘message’ “

After Runnig this it worked

Respondent: arslan ahmed mir

Solution #6:

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'.
Respondent: Saikat

Solution #7:

By just adding an empty commit will fix issue by using

$ git commit -m "empty commit" --allow-empty
$ git push

// above make empty commit without edit then push

Respondent: Spring

Solution #8:

Run the command git show-ref, the result refs/heads/YOURBRANCHNAME
If your branch is not there, then you need to switch the branch by

git checkout -b "YOURBRANCHNAME"

git show-ref, will now show your branch reference.

Now you can do the operations on your branch.

Respondent: Sonu

Solution #9:

In my case the error was caused because I was typing

git push origin master

while I was on the develop branch
try:

git push origin branchname

Hope this helps somebody

Respondent: aneesh joshi

Solution #10:

The error demo:

[email protected] MINGW64 /d/1 (dev)
$ git add --all

[email protected] MINGW64 /d/1 (dev)
$ git status
On branch dev
Initial commit
Changes to be committed:
  (use "git rm --cached <file>..." to unstage)

    new file:   index.html
    new file:   photo.jpg
    new file:   style.css

[email protected] MINGW64 /d/1 (dev)
$ git push origin dev
error: src refspec dev does not match any.
error: failed to push some refs to '[email protected]:yourRepo.git'

You maybe not to do $ git commit -m "discription".

Solution:

[email protected] MINGW64 /d/1 (dev)
$ git commit -m "discription"
[dev (root-commit) 0950617] discription
 3 files changed, 148 insertions(+)
 create mode 100644 index.html
 create mode 100644 photo.jpg
 create mode 100644 style.css

[email protected] MINGW64 /d/1 (dev)
$ git push origin dev
To [email protected]:Tom007Cheung/Rookie-s-Resume.git
 ! [rejected]        dev -> dev (fetch first)
error: failed to push some refs to '[email protected]:yourRepo.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
Respondent: Mai

Solution #11:

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.

  1. 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.
  2. Commit your changes => git commit -m 'Initial Commit'.
  3. Now push your changes => git push -u origin master
Respondent: DINA TAKLIT

Solution #12:

Check that you call the git commands from the desired directory (where the files are placed).

Respondent: NoamG

Solution #13:

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!

Respondent: Tomasz Wójcik

Solution #14:

Setup username and password in the git config

In terminal, type

vi .git/config

edit url with

url = https://username:[email protected]/username/repo.git

type :wq to save

Respondent: Prashanth Sams

Solution #15:

Only because your local branch does not math the one in your remote repository.
git push origin HEAD:master
Enable you to ignore the conflict and upload your commit anyway.

Respondent: YoungJeXu

Solution #16:

For me, the fix appears to be “git .” (stages all current files). Apparently this is required after a git init?
I followed it by “get reset” (unstages all files) and proceeded with the exact same commands to stage only a few files, which then pushed successfully.

   git . 
   git reset
Respondent: JohnP2

Solution #17:

For a new repository, the method works for me:

  1. Remote the files related with git
    rm -rf .git

  2. Do the commit again
    git add . && git commit -m "your commit"

  3. Add the git URL and try to push again
    git remote add origin <your git URL>

  4. And then try to push again

    git push -u origin master -f

  5. Success!

Since it’s a new repository, so it doesn’t matter for me to remove the git and add it again.

Respondent: backslash112

Solution #18:

It happened to me and I discovered that github was trying to verify my account. So you need these 2 commands:

git config --global user.email <your github email>
git config --global user.name <your github username>
Respondent: jess

Solution #19:

FWIW, ran into same error, but believe it came about due to the following sequence of events:

  • Remote Git repo was created with master branch.
  • Local clone was then created.
  • Remote Git repo was then modified to include a dev branch, which was defined as the default branch, in conjunction with permissions added to the master branch preventing changes without a pull request.
  • Code updates occurred in the local clone, ready to be pushed to the remote repo.

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.

Respondent: Trentium

Solution #20:

This error is also caused due to an unmatched local branch name.
Make sure that you are giving correct local branch name (check spelling and case sensitivity)
I had the same error because my local branch name was “validated” and was trying to push the changes using git push -f origin validate, updated that to git push -f origin validated worked.

Hope this helps.

Respondent: Rupesh

Solution #21:

I also faced the same error.
In my case below is the scenario.

I have master branch which set as origin.

Other side I have release branch “Release_branch”.

I have to fork my feature branch(i.efeature/testBranch) from Release branch.

Below are the steps I did.

$ git checkout Release_branch
$ git pull
$ git checkout feature/testBranch
$ git commit -m "SOME_MESSAGE"
$ git push -u origin feature/testBranch
Respondent: rahulnikhare

Solution #22:

I had this error (error: src refspec master does not match any) with a new repository, when trying git push origin master, because GitHub changed the default name of the master branch to main.

So, git push origin main is working for me.

Respondent: Leon Gilyadov

Solution #23:

Ensure that if you are pushing the master branch the ensure that you’re currently in the master branch if not checkout to the master branch and now push your commits. To list all current branches use :

git branch 

Your currently working branch should have an asterisk at the beginning for instance if am working on my

*devstage
master

In this case, push the commits in the devstage branch first then perform a git pull request if you want to merge the two branches that is the master and the devstage.

Respondent: stanley mbote

Solution #24:

this error occurs when you clone a repo from one branch and you trying to push changes to another branch just try to make sure that you are in the same branch compared to the branch that you are trying to push if it isnot the same just clone your repo again from that specific branch by using git clone -b <branchname> <remote-repo-url> then retry to push changes

Solution #25:

I had the same problem recently. but now resolved this issue. Because, Now GitHub changed master to main. It works well for me. Use git push origin main instead of git push origin master. Hopefully, It will work.

Respondent: Vintage Coder

Solution #26:

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
Respondent: Vivek Singh

The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .

Most Popular

To Top
India and Pakistan’s steroid-soaked rhetoric over Kashmir will come back to haunt them both clenbuterol australia bossier man pleads guilty for leadership role in anabolic steriod distribution conspiracy