Message 'Src Refspec Master Does Not Match Any' When Pushing Commits in Git
I Clone My Repository with: Git Clone Ssh: //Xxxxx/Xx. Git but After I Change Some Files and Add and Commit Them, I Want to Push Them to the Server: Git Add...
I clone my repository with:
git clone ssh://xxxxx/xx.git
But after I change some files and add and commit them, I want to push them to the server:
git add xxx.php
git commit -m "TEST"
git push origin master
But the error I get back is:
error: src refspec master does not match any.
error: failed to push some refs to 'ssh://
124 Answers
Maybe you just need to commit. I ran into this when I did:
mkdir repo && cd repo
git remote add origin /path/to/origin.git
git add .
Oops! Never committed!
git push -u origin master
error: src refspec master does not match any.
All I had to do was:
git commit -m "initial commit"
git push origin main
Success!
- Try
git show-refto see what refs you have. Is there arefs/heads/master?
Due to the recent "Replacing master with main in GitHub" action, you may notice that there is a
refs/heads/main. As a result, the following command may change fromgit push origin HEAD:mastertogit push origin HEAD:main
- You can try
git push origin HEAD:masteras a more local-reference-independent solution. This explicitly states that you want to push the local refHEADto the remote refmaster(see the git-push refspec documentation).
I also had a similar error after deleting all files on my local computer, and I have to clean up all files in the repository.
My error message was something 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 executing 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.
git push -u origin master
error: src refspec master does not match any.
For that you need to enter the commit message as follows and then push the code:
git commit -m "initial commit"
git push origin master
Successfully pushed to master.
I found this happened in a brand new repository after I Git added only a directory.
As soon as I added a file (e.g. a README), Git push worked great.
Missing or skipping git add . or git commit may cause this error:
git push -u origin master
Username for ' yourusername
Password for '
error: src refspec master does not match any.
error: failed to push some refs to '
To fix it, reinitialize and follow the proper sequence:
git init
git add .
git commit -m 'message'
git *create remote
git push -u origin master
To fix it, re-initialize and follow the proper code sequence:
git init
git add .
git commit -m 'message'
git push -u origin master
This happens too when you are in a specific branch and try to push another branch that does not exist yet, like:
$ git branch
* version-x # you are in this branch
version-y
$ git push -u origin master
error: src refspec master does not match any.
error: failed to push some refs to 'origin_address'
Make sure you've added first, and then commit/ push:
Like:
git init
git add .
git commit -m "message"
git remote add origin ""
git push -u origin master
I faced the same problem, and I used --allow-empty:
$ git commit -m "initial commit" --allow-empty
...
$ git push
...
Supplement
One of main reasons of this problem is that some Git servers, such as BitBucket, don't have their master branch initialized when a fresh repository is cloned.
I faced the same issue some days ago.
If you created a new repository nowadays(2020) then the default branch is main on GitHub.
you can check on GitHub now in your repository branches.
and you can also check branch on the terminal by running the command:
git branch
so that's why you need to run
git push origin main
instead of
git push origin master
Goodluck
Must Read
Problem faced
I had the same problem when I was creating a new repository on GitHub and linking it with my react-app in the client computer I have.
I used the following steps:
Commands used before the problem
git init
git commit -m "first commit"
git branch -M main
git remote add origin "_git repository link here_"
git push -u origin main
My mistake
But as you can see my mistake was not using the git add . command
I did this mistake because I already had README.md file and GitHub instructs us with basic commands while creating the repository.
My solution
My solution is to use git add . after git init command.
Use the following set of commands in the same order to overcome the problem:
git init
git add .
git commit -m "first commit"
git branch -M main
git remote add origin "_git repository link here_"
git push -u origin main
Two possibilities :
1- Either you forgot to include the .gitignore file.
Here are all the steps required:
Create an empty Git repository on remote,
On local create the .gitignore file for your project. GitHub gives you a list of examples here
Launch a terminal, and in your project do the following commands:
git remote add origin YOUR/ORIGIN.git git add . git commit -m "initial commit or whatever message for first commit" git push -u origin master
2- Or you are trying to create a new Github project.
Github replaced master with main as the default branch name. To resolve the issue :
- On your local project:
- remove the
.gitfolder if it exists - recreate a clean repository by launching the following in your project:
- remove the
in the terminal:
git init
git add .
git commit -m "YOUR FIRST MESSAGE HERE"
git branch -M main
git remote add origin _GIT_LINK_TO_PROJECT_HERE_
git push -u origin main
For me,following worked to move untracked files:
git add --all
Next, I followed similar steps
git commit -m "First commit"
Then,
git remote add origin git@github.....
Last but not the least:
git push -u origin master
As you do this, Windows security will pop up asking for your username and password.
You probably forgot the command git add . after the git init command.
After the GitHub update 01.10.20 you should use main instead of master.
Do it like these way...
Create a repository on GitHub- Delete existing
.gitfile on your local directory - Go to local project directory and type
git init git add .git commit -m"My First Commmit"- Now check your branch name it will be
masterin your local project git remote add origin <remote repository URL past here from the github repository>then typegit remote -vgit push -f origin master- Now check the github repository you will see two branch 1.
main2.master - In your local repository create new branch and the branch name will be
main git checkout maingit merge mastergit pull origin maingit push -f origin main
Note: from 01.10.20 github decided use main instead of master branch use default branch name
Just add an initial commit. Follow these steps:
git add .git commit -m "initial commit"git push origin master
This worked for me.
My issue was that the 'master' branch hadn't been created locally yet.
A quick
git checkout -b "master"
created the master branch, at which point, a quick
git push -u origin master
pushed the work up to the Git repository.