3904

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'
18
  • 65
    @Marco That's not a duplicate. That one is a very specific issue about pushing a local branch to a remote branch. This one is about initializing a repo and pushing it up. They produce the same error, but the REASONS they produce that error and the fixes are entirely different. Also, sinoohe, you should accept an answer. Probably the first one, seeing as it answers the question and has helped over 350 people. Jul 8, 2013 at 0:42
  • 4
    Hope this post would be useful to somebody- samranga.blogspot.com/2015/07/… The error in the question can be popped even when tried to Create a git BitBucket repository from an already locally existing project Jul 2, 2015 at 13:00
  • 43
    Yet another simple task made difficult by Git. The Git devs should use Stack Overflow as feedback in their SDLC loop. 850,000+ people should indicate something is seriously wrong with Git's workflow. They need to hire a UX expert because they clearly cannot git it right on their own.
    – jww
    Sep 16, 2017 at 9:28
  • 10
    If you didnt add git add with dot or some files this error also will appear.
    – Blasanka
    Apr 28, 2018 at 10:18
  • 29
    Recently Github/Git does not have a default "master" branch. "master" has been changed to "main" branch. So this may be a possible reason for this error.
    – Harini Sj
    Nov 23, 2020 at 4:39

133 Answers 133

1 2 3 4
5
1

Some commands in order to follow
-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

Make sure you type all commands this error is because sometimes you might miss add. or commit and make sure your branch is main.

0

I just got this error while trying to push stuff into a new repository on GitHub. I had created the Git repository locally, plus I had created the repository on GitHub using the Web GUI (including a LICENSE file).

The problem went away after I pulled the LICENSE file from the otherwise empty GitHub repository into my local repository. After that, I could push with no problems.

0

In my case fastlane match nuke development (which deletes the development certificates and profiles from the git credential store and the Developer Portal) tried to push master but we don't have master. Since we have two different teams we have also 2 different branches. What solved the problem was to call tell match about the correct branch:

fastlane match --git_branch <your_branch> nuke development
2
  • What is "fastlane match nuke development", etc.? Some kind of weird Git client? Nov 18, 2019 at 0:35
  • Nope, in fact fastlane match nuke development deletes the development certificates and profiles from the git credential store and the Developer Portal (I edited my answer).
    – blackjacx
    Nov 19, 2019 at 10:12
0

Updated answer: Make sure all changes are committed.

Then type : git push Before this make sure to make a personal access token, GitHub uses this now. Then type out your GitHub username (after typing git push) then paste your personal access token in the password input.

After all this you should be able to see your changes in GitHub!

0

I was facing this issue because I had made a branch and I had to use that branch and after that it was resolved by using this.

git push origin branch_name

0

I think this might help someone. I made my first major commit today. I tried a lot of the guide given, but it kept spitting errors.

  • First: cd into the directory with your files
  • Initialize git: git init
  • commit the files: git commit
  • To enforce the commit if there are any hazy bash commands: click I to insert your commit message
  • To continue: click Esc

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 'name@mail.com'

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!!!

0

For me, it seemed to be because I had already done the commit process, so I got this after trying to commit again.

Your branch is ahead of 'origin/main' by 1 commit.
  (use "git push" to publish your local commits)

Since I saw that the path was origin/main, I pushed to main instead of masters and it worked.

NB: Check to ascertain if the primary branch is main or master.

As of 2022.

1
  • Re "masters": Do you mean "master" (without "s")? Sep 18, 2022 at 18:36
0
 sudo git push -v --progress "origin" : origin/prod_18aug2022

This worked for me when pushing from a local to remote branch.

0

My branch was named bugfix-22112022/5v8ST5Q6/181-kontaktformular-eingabe-nach-anmeldung-übernehmen, <-- yes it had a comma in it and I thought the comma is not part of it and deleted it when trying to push...

I renamed my branch:

git branch -m bugfix-22112022/5v8ST5Q6/181-kontaktformular-eingabe-nach-anmeldung-übernehmen
0

You may encounter this problem when any of your folder is already linked to other git repository. Visit the folder that is not being added and delete the .git file (if you donot want it to link to that repo any more) from there and try adding and commiting again

0

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

Use above commands you might be missing "git branch -M main" (this particular command)

0
-1

I had an extremely long local branch name.

git branch -m new_shorter_branch_name

fixed the problem.

1
-3

I had the same error; this is how mine was solved:

git config --global user.email "YOUR EMAIL"
git config --global user.name "YOUR NAME"
1
  • this does not solve the error these commands are only for showing the current git user and email Jan 16 at 18:56
1 2 3 4
5

Not the answer you're looking for? Browse other questions tagged or ask your own question.