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://xxxxx.com/project.git'
git add
with dot or some files this error also will appear. - anyone Maybe you just need to commit. I ran into this when I did:
mkdir repo && cd repo
git init
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!
Answered 2023-09-20 20:13:18
git add --all
in case you wish to add all the files Or you can selectively add files. Then git commit -m "Initial comment"
, git push origin master
. This will surely work. - anyone git commit -m 'initial commit'
should be double quoted. 'git commit -m "initial commit"
, at least on windows. - anyone git show-ref
to see what refs you have. Is there a refs/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:master
togit push origin HEAD:main
git push origin HEAD:master
as a more local-reference-independent solution. This explicitly states that you want to push the local ref HEAD
to the remote ref master
(see the git-push refspec documentation).Answered 2023-09-20 20:13:18
git show-ref
showed my branch; the git push origin HEAD:<branch>
worked for me. - anyone git push origin HEAD:master
. But why something like git push --force origin master
does not work? - anyone master
is changed to main
now. - anyone 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.
Answered 2023-09-20 20:13:18
git push origin BRANCH --force
worked. Thank you! - anyone 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.
Answered 2023-09-20 20:13:18
For me I had to make sure the public key is properly configured on the server (appended in ~/.ssh/authorized_keys) and in GitHub/Bitbucket (added to my SSH keys on GitHub or Bitbucket) - they need to match. Then:
git add --all :/
git commit -am 'message'
git push -u origin master
Answered 2023-09-20 20:13:18
This happened to me in a brand new repository after I ran git add
with only an empty directory.
As soon as I added a file (e.g. a git add README.md
), then git push
worked great.
Answered 2023-09-20 20:13:18
Missing or skipping git add .
or git commit
may cause this error:
git push -u origin master
Username for 'https://github.com': yourusername
Password for 'https://yourusername@github.com':
error: src refspec master does not match any.
error: failed to push some refs to 'https://github.com/yourusername/foobar.git'
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
Answered 2023-09-20 20:13:18
git remote add __REMOTE_NAME__ __URL_OR_SSH__
, and above the remote name is "origin" - anyone -u
option that was used here. - anyone git *create remote
? - anyone To fix it, re-initialize and follow the proper code sequence:
git init
git add .
git commit -m 'message'
git push -u origin master
Answered 2023-09-20 20:13:18
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'
Answered 2023-09-20 20:13:18
-u
may have helped here. - anyone master
, so you can't push it. You either want to push an existing branch – or create the master branch and then push it, like this: git checkout -b master; git push -u origin master;
- anyone git push origin scheduler
. HA! One letter off will kill you in programming. lol - anyone 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:
git init
git commit -m "first commit"
git branch -M main
git remote add origin "_git repository link here_"
git push -u origin main
But as you can see, my mistake was not using the git add .
command.
I did this mistake, because I already had the README.md file and GitHub instructs us with basic commands while creating the repository.
My solution is to use git add .
after the 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
Answered 2023-09-20 20:13:18
git add .
then git commit -m "first commit"
, then push again - anyone git branch -M main
worked for me. - anyone git branch -M main
is important which is why it wasn't working for me. It expects master
if you don't put anything. - anyone I faced the same problem, and I used --allow-empty
:
$ git commit -m "initial commit" --allow-empty
...
$ git push
...
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.
Answered 2023-09-20 20:13:18
Make sure you've added first, and then commit/ push:
Like:
git init
git add .
git commit -m "message"
git remote add origin "github.com/your_repo.git"
git push -u origin master
Answered 2023-09-20 20:13:18
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 the branch in 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
Answered 2023-09-20 20:13:18
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:
.git
folder if it existsIn 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
Answered 2023-09-20 20:13:18
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.
Answered 2023-09-20 20:13:18
You probably forgot the command git add .
after the git init
command.
Answered 2023-09-20 20:13:18
After the GitHub update 2000-10-01, you should use main instead of master.
Do it like this way...
.git
file in your local directorygit init
git add .
git commit -m"My first commit"
master
in your local projectgit remote add origin <remote repository URL past here from the GitHub repository>
, and then type git remote -v
git push -f origin master
main
2. master
main
git checkout main
git merge master
git pull origin main
git push -f origin main
Note: from 2020-10-01, GitHub decided use main instead of master branch to use as the default branch name.
Answered 2023-09-20 20:13:18
Just add an initial commit. Follow these steps:
git add .
git commit -m "initial commit"
git push origin master
This worked for me.
Answered 2023-09-20 20:13:18
If your branch is "main":
Run this command:
git push origin main
If your branch is "master":
Run this command:
git push origin master
Answered 2023-09-20 20:13:18
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.
Answered 2023-09-20 20:13:18
I have faced the same issue, and this solved my problem:
Just make a branch:
git checkout -b "master"
After that,
git push -u origin master
Boom.
Answered 2023-09-20 20:13:18
Maybe the branch is main instead of master.
Try
git push origin HEAD:main
or
git push origin main
Answered 2023-09-20 20:13:18
GitHub changed the default branch name from master
to main
.
So if you created the repository recently, try pushing the main
branch:
git push origin main
Answered 2023-09-20 20:13:18
This happens when you have added your file, forgot to commit and pushing. So commit the files and then push.
Answered 2023-09-20 20:13:18
git add .
git commit -m "message"
git push origin branch
Please check for spelling mistakes because that could also give that error.
Answered 2023-09-20 20:13:18
If you get this error while working in detached HEAD mode, you can do this:
git push origin HEAD:remote-branch-name
See also: Making a Git push from a detached head
If you are on a different local branch than the remote branch, you can do this:
git push origin local-branch-name:remote-branch-name
Answered 2023-09-20 20:13:18
It happens if you forget to commit before pushing for the first time. Just run:
git commit -m "first commit"
Answered 2023-09-20 20:13:18
To check the current status, git status
.
And follow these steps as well:
git init
git add .
git commit -m "message"
git remote add origin "github.com/your_repo.git"
git push -u origin master
Answered 2023-09-20 20:13:18
This just mean you forgot to do the initial commit, try
git add .
git commit -m 'initial commit'
git push origin master
Answered 2023-09-20 20:13:18
I had the same problem when I missed to run:
git add .
(You must have at least one file, or you will get the error again.)
Answered 2023-09-20 20:13:18