• Register
1 vote
1.1k views

Problem :

I have cloned my current repository with below command :

git clone ssh://xxxxxx.com/project.git

But after I changed some of my files and added and committed them, I also wanted  to push them to my server with the help of below commands :

git add xxxx.php

git commit -m "TEST"

git push origin master

But I am facing below error :

error: src refspec master does not match any. 

error: failed to push some refs to 'ssh://xxxxxx.com/project.git'

6 5 3
7,540 points

Please log in or register to answer this question.

2 Answers

0 votes

Solution :

Maybe you just need to do the commit. I ran into this in recent past when I executed below commands:

mkdir myrepo && cd myrepo
git remote add origin /path/to/the/origin.git
git add .

Oops! Here I Never committed! So got the below error after executing below command.

git push -u origin master
error: src refspec master does not match any.

So all I did was executing below commands:

git commit -m "initial commit"
git push origin master

As you can see I committed my changes and I got Success!

OR

1. You can try git show-ref to see what are the refs you having. Check if its there a refs/heads/master?

2. You can also  try the git push origin HEAD:master as the more local-reference-independent solution. This will explicitly state that you want to push your local ref HEAD to yur remote ref master

9 7 4
38,600 points
0 votes

Solution:

Maybe you only require to commit. I ran into this when I did:

mkdir repo && cd repo
git remote add origin /path/to/origin.git
git add .
git push -u origin master
error: src refspec master does not match any.

All You need to do this:

git commit -m "initial commit"
git push origin master
  1. Attrmpt git show-ref to see what refs you have. Is there a refs/heads/master?

  2. You can attempt git push origin HEAD:master as a more local-reference-independent solution. This apparently states that you want to push the local ref HEAD to the remote ref master (see the git-push refspec documentation).

I also had a same error after deleting all files on my local computer, and I have to tidy up all files in the repository.

My error message was  like this:

error: src refspec master does not match any.
error: failed to push some refs to 'git@github ... .git'

And it was solved by acting the following commands:

touch README
git add README

git add (all other files)
git commit -m 'reinitialized files'
git push origin master --force  # <- caution, --force can delete others work.
  1. My changes were formerly committed

  2. Force push still gave me the similar error.

So I attempted Vi's solution:

git push origin HEAD:<remoteBranch> 
git push -u origin master
error: src refspec master does not match any.

For that you require to enter the commit message as follows and then push the code:

git commit -m "initial commit"

git push origin master

From git branch it looks 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 :-)

Only to ensure that the name is truly the only thing that went astray, you can run git log and look at the last few commits - and compare them to the last several commits on bitbucket website.

10 6 4
31,120 points

Related questions

0 votes
1 answer 22 views
22 views
Problem: "Git src refspec master does not match any". Can someone pleas help me out? I have tried everything from git commit to rm -rf * and I cannot get anything to work at all.
asked Apr 22 Supti 13k points
1 vote
1 answer 12 views
12 views
Problem: Why I got the error : error: src refspec master does not match any. error: failed to push some refs
asked Apr 12 MUHAMMAD MUNEEB 83k points
0 votes
1 answer 4 views
4 views
Problem: "Git error: src refspec master does not match any error: failed to push some refs", could you tell me the easiest way to solve this problem?
asked Apr 22 Moumita Bhowmick 12.9k points
0 votes
1 answer 7 views
7 views
Problem: 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 ... /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.
asked Apr 15 munim01 21k points
0 votes
1 answer 2 views
2 views
Problem: Why I am facing this probem>error src refspec master does not match any?Give me an idea please.
asked Apr 4 ashik 14.6k points
1 vote
1 answer 2 views
2 views
Problem: How can I deal with this problem : git src refspec master does not match any.
asked Apr 12 MUHAMMAD MUNEEB 83k points
0 votes
1 answer 5 views
5 views
Problem: Somebody please fix the error. Error: failed to push some refs.
asked Mar 27 ashik 14.6k points
0 votes
1 answer 8 views
8 views
Problem: I found many questions with similar subject, but I didn't found any practical guidance about this issue: why git status informs me nothing to commit, working directory clean, even tough I have made a modification at my local branch? Please help?
asked Apr 11 Sana8989 8.9k points
0 votes
0 answers 7 views
7 views
Problem: I dont know how to merge branch to master in git?
asked Mar 30 jamuna1 30.2k points
0 votes
1 answer 44 views
44 views
Problem : git - Your branch is ahead of 'origin/master' by 1 commit
asked Feb 15 Sabbir Hossain 14.6k points