Reputation: 42592
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'
Upvotes: 4222
Views: 4969882
Reputation: 1
If your branch is called "main":
Run this command:
git push origin main
If your branch is called "master" instead, run this command:
git push origin master
Upvotes: 29
Reputation: 215
Solution for Android Studio Mac.
I faced when i am trying to push the code to exiting empty repo.
error: src refspec main does not match any error: failed to push some refs to 'github.com:username/repoName.git'
once i am trying to push code using command
git push origin main --force
I faced another issue
[email protected]: Permission denied (publickey).
solution:
git remote -v
set the url using https instead of [email protected] replace with your git username and repoName
git remote set-url origin https://github.com/username/repoName.git
git push -u origin main
git will ask for you username and password
Username for 'https://github.com': Enter your username
password for 'https://[email protected]': enter your gitHub access token instead of password because Support for password authentication was removed on August 13, 2021.Password for
That,s it then push code
git push -u origin main
Upvotes: 0
Reputation: 792
All you need is:
git add .
That code tracks all untracked files in your directory.
Upvotes: 14
Reputation: 4508
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) or you can also use # git add --all :/
git commit -m 'reinitialized files'
git push origin master --force # <- caution, --force can delete others work.
Upvotes: 289
Reputation: 1329292
A git clone
of an empty GitHub repository will create a local repository with 'main
' as a default branch, even if init.defaultBranch
is set on master
!
The Git transfert protocol v2, supported by GitHub, will communicate to the client the name of the remote default branch (now main
for GitHub) to the local Git repository created by git clone
.
That means adding and committing new commits will be done on 'main
' branch, even if the Git client still consider master
as the default branch.
No more "src refspec master does not match any.
" on your next push.
my suggestion is, after using these codes:
git init
git remote add origin <your-repo-url>
clone your repo by this code:
git clone <your repo url>
then cd repo-folder and copy the .git and all content to your main directory (cd ..) and delete the repo-folder. Now you can add, commit and push your files.
Upvotes: 3
Reputation: 71
I got the same error. Its because in my system I'm currently on "master" branch and I'm trying to push to main branch "git push -u origin main". So the solution is create a new branch called main by "git checkout -b main" , so main branch is created and you will be inside this branch. (You can check all the branches using "git branch"). Now repeat the previews steps like "git add ." to stag all files and "git commit -m "message" to commit with a message and finally "git push -u origin main".
I hope it solved your error. Happy coding :)
Upvotes: 1
Reputation: 31
This issue can be solved by reinitializing Git in the project folder:
# Type the following on the CMD
git init
# Then try pushing your code online
git push
Upvotes: 2
Reputation: 108
I made my first major commit today. I tried a lot of the guide given, but it kept spitting errors.
git init
git commit
To send to your GitHub repository, first ensure that your username and email has been added:
git config --global user.name 'Your name'
git config --global user.email '[email protected]'
Continue:
git remote add origin https://github repo url
To push to the repository:
git push -u origin 'https://github.repo url'
It loads the commits to your repository.
Done!!!
Upvotes: 2
Reputation: 812
sudo git push -v --progress "origin" : origin/prod_18aug2022
This worked for me when pushing from a local to remote branch.
Upvotes: 0
Reputation: 216
In my case, the error occurred when I was pushing changes to the branch which I only had locally. The remote branch did not exist with the same name. I resolved the error with the following command:
git push --set-upstream origin "your-branch-name"
Upvotes: 1
Reputation: 515
Error from Git:
error: src refspec master does not match any.
Fixed with this step:
git commit -m "first commit"
Before I ran:
git add <files>
And after I ran:
git push -u origin master
Upvotes: 1
Reputation: 143
I recently came across this problem. I checked show-ref using git show-ref
and checked whether
refs/heads/master
was present.
It was present, but still it was not working for me.
As I was writing
git push origin main
Later I changed this command with
git push origin master
and it worked perfectly fine for me.
Upvotes: 3
Reputation: 621
I had the same problem and discovered also that I had not committed any file, so when I tried to commit again, I got this error message:
*** Please tell me who you are.
Run
git config --global user.email "[email protected]"
git config --global user.name "Your Name"
to set your account's default identity.
Omit --global to set the identity only in this repository.
fatal: unable to auto-detect email address (got 'USER@WINDOWS-HE6I2CL.(none)')
Then all I did was add my email and name globally and then committed again:
git commit -m 'Initial commit'
Then pushed
git push -u origin master
Upvotes: 3
Reputation: 14237
I was contributing to one GitHub repository, so I forked the project, cloned it, created my own branch, did some commits, and tried to push.
At this point I discovered that I cloned not my fork, but the original project repository (which I don't have permission to push to).
So I changed the .git/config
to point origin
to my repository.
At this point, when I tried to push, I was getting the error error: src refspec my_awesome_branch does not match any.
All I had to do was to touch any file and commit it (similar like you see it in this answer):
git touch README
git commit -m "fixing error in my git repo"
And then:
git checkout master
git pull origin master
git push origin master # This will tell my remote repository about my new branch
git checkout my_awesome_branch
git push origin my_awesome_branch # Now it will work
Upvotes: 3
Reputation: 806
Regarding Aryo's answer: In my case I had to use the full URL of my local Git repository to push the file. First I removed all the files in the current directory and created README added it.
Added some more. Then I committed those files and at last pushed them, giving a proper URL to the repository. Here yourrepository is the name of the repository on the server.
rm -rf *
touch README
git add README
touch file1 file2
git add file1 file2
git commit -m "reinitialized files"
git push git@localhost:yourrepository.git master --force
Upvotes: 3
Reputation: 356
I faced a similar error. The error was due to this command:
git push -u origin master
Subsequent commands worked for me.
Start with these commands
git init
git add .
git commit -m "second commit"
So before pushing it, run these commands to see what remote repository on GitHub our local repository is connected to and which branch are you on.
git remote
git branch
remote --> origin
branch --> main
git push -u remote branch
Or more specifically:
git push -u origin main
Upvotes: 4
Reputation: 4075
Check your commit title, because if you forget the git commit -m "xxxx"
command, you get the same problem
git commit -m "initial commit"
Upvotes: 6
Reputation: 450
I had a similar error. But Git tells me:
*** Please tell me who you are.
Run
git config --global user.email "[email protected]"
git config --global user.name "Your Name"
Or to set your account's default identity.
Omit --global to set the identity only in this repository.
Then the error goes away.
Upvotes: 6
Reputation: 163
What worked for me was simply checkout to the branch that I want my code to push and then simply push your code.
git checkout -b branchname-on-which-i-will-push-my-code
git add .
git commit -m "my commit message"
git push origin branchname-on-which-i-will-push-my-code
Upvotes: 7
Reputation: 1295
I did face the same problem, but in my case the following the exact steps from the beginning as given on the page when you create a new repository worked.
Just pasting that over here:
echo "# YYYY" >> README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin https://github.com/XXXX/YYYY.git
git push -u origin master
Type the above in Git Bash. XXXX being the username and YYYY the repository name.
Upvotes: 7
Reputation: 1612
I got this problem while adding an empty directory. Git doesn't allow to push an empty directory. Here is a simple solution.
Create the file .gitkeep inside of directory you want to push to remote and commit the "empty" directory from the command line:
touch your-directory/.gitkeep
git add your-directory/.gitkeep
git commit -m "Add empty directory"
Upvotes: 7
Reputation: 683
Try this:
git add .
git commit -m "your commit message"
git remote add origin *remote repository URL*
git push origin *your-branch-name*
Upvotes: 8
Reputation: 2709
This error occurs as you are trying to push an empty repository into the Git server. This can be mitigated by initializing a README.md file:
cat > README.md
Then type something, followed by Enter, and a Ctrl + D to save.
Then the usual committing steps:
git add .
git commit -m "Initial commit"
git push origin master
Upvotes: 9
Reputation: 311
May be your current branch has no upstream branch. Try these commands when you are going to push for the first time.
git init
git add .
git status
git commit -m "initial commit"
git remote add origin "github.com/your_repo.git"
git push --set-upstream origin master
Upvotes: 11
Reputation: 341
I had the same issue. Turns out that I was pushing to master branch, while the original branch was main. You can check it using git show-ref
.
If it shows refs/head/master
, just change your branch to main. Here is what you can do:
git add .
git commit -m "message"
git branch -M main
git push -u origin main -f
Upvotes: 12
Reputation: 2512
In case if you are facing this problem even after doing git init
and pushing your initial commit. You can then try the following,
git checkout -b "new branch name"
git push origin "new branch name"
Your code will be pushed as a new branch.
Upvotes: 13
Reputation: 157
You need to configure your Git installation if it is the first time that you use it, with:
git config --global user.email "[email protected]"
git config --global user.name "Your Name"
Upvotes: 14
Reputation: 903
This just mean you forgot to do the initial commit, try
git add .
git commit -m 'initial commit'
git push origin master
Upvotes: 22
Reputation: 14309
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.
Upvotes: 28
Reputation: 833
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.
Upvotes: 44