189

I just started using git with github. I followed their instructions and ran into errors on the last step. I'm checking in an existing directory that isn't currently source-controlled (project about a week old). Other than that, my use case should be pretty run of the mill.

Here's what's happening:

$ git push origin master
error: src refspec master does not match any.
fatal: The remote end hung up unexpectedly
error: failed to push some refs to '[email protected]:{username}/{projectname}.git'

Github's instructions:

Global setup:

  Download and install Git
  git config --global user.name "Your Name"
  git config --global user.email {username}@gmail.com

Next steps:

  mkdir projectname
  cd projectname
  git init
  touch README
  git add README
  git commit -m 'first commit'
  git remote add origin [email protected]:{username}/{projectname}.git
  git push origin master
7
  • 4
    It appears that the initial commit didn't work for whatever reason. Git log helped me see whether or not the commit works. I was successful trying it again the next day. Thanks!
    – sutee
    May 6, 2009 at 18:30
  • 1
    If you do not add any files, commit or run git init, yoy always get these kind of problems. Therefore, always run git status to see if everything is OK.
    – raduken
    Jan 26, 2012 at 20:07
  • similar error when creating a branch to a newly created git repository from existing code. Resolved the error by cloning the git repository.
    – user553620
    Nov 27, 2013 at 16:45
  • Possible duplicate of src refspec master does not match any when pushing commits in git
    – user456814
    Jun 6, 2014 at 4:42
  • Possible duplicate of Error when “git push” to github.
    – user456814
    Jun 6, 2014 at 4:46

29 Answers 29

194

I was having the same issue and then smacked myself in the head because I hadn't actually added my project files.

git add -A
git commit -am "message"
git push origin master
1
  • Yeah, I had tried the following, but the solution for me was to use your command instead: git add * Correct syntax was: git add . Mar 31, 2010 at 19:59
140

The error message leads to the conclusion that you do not have a master branch in your local repository. Either push your main development branch (git push origin my-local-master:master which will rename it to master on github) or make a commit first. You can not push a completely empty repository.

3
  • 10
    I had the "empty repository" problem, since the relevant guide referenced by GitHub (beans.seartipy.com/2008/12/09/…) did not mention the "git commit -m 'first commit'" command. Once I used that, all was fine! Sep 1, 2009 at 13:55
  • 3
    I had just forgotten to commit my changes. Jan 11, 2012 at 4:32
  • When you say git push origin my-local-master:master what does it mean by my-local-master? If I have a name of CSS-pix of my folder which I want to push
    – localhost
    Oct 6, 2017 at 10:24
30

I had the same issue. I deleted the .git folder then followed the following commands

  1. $ git init
  2. $ git add .
  3. $ git remote add origin [email protected]:project/project.git
  4. $ git commit -m "Initial version"
  5. $ git push origin master
10

I have same issue . it's solved my problem . İf you init your git . you have to do on Terminal

1) git add .

2)git commit -m "first commit"

For send to bitbucket

3) git push -u origin --all # pushes up the repo and its refs for the first time

0
6

I just had the same problem while creating my first Git repository ever. I had a typo in the Git origin remote creation - turns out I didn't capitalize the name of my repository.

 git remote add origin [email protected]:Odd-engine

First I removed the old remote using

git remote rm origin

Then I recreated the origin, making sure the name of my origin was typed EXACTLY the same way my origin was spelled.

git remote add origin [email protected]:Odd-Engine

No more error! :)

4

I had the same error, as Bombe said I had no local branch named master in my config, although git branch did list a branch named master...

To fix it just add this to your .git/config

[branch "master"]
    remote = origin
    merge = refs/heads/master

Kinda hacky but does the job

3

make sure you are on a branch, at least in master branch

type:

git branch

you should see:

ubuntu-user:~/git/turmeric-releng$ git branch

* (no branch)
master

then type:

git checkout master

then all your changes will fit in master branch (or the branch u choose)

3

It looks like this question has a number of answers already, but I'll weigh in with mine since I haven't seen any that address the issue I had.

I had this error as well on a brand new github repository. It turns out the user I was pushing from did not have push access. For some reason, this results in an "ERROR: repository not found" error instead of some sort of access error.

Anyway, I hope this helps the poor soul who runs into the same issue.

2
error: failed to push some refs to '[email protected]:{username}/{projectname}.git'

Unless you're generalizing the error message, it looks like you literally put [email protected]:{username}/{projectname}.git as your remote Git repo. You should fill in {username} with your GitHub username, and {projectname} with your project's name.

2

To actually resolve the issue I used the following command to stage all my files to the commit.

$ git add .
$ git commit -m 'Your message here'
$ git push origin master

The problem I had was that the -u command in git add didn't actually add the new files and the git add -A command wasn't supported on my installation of git. Thus as mentioned in this thread the commit I was trying to stage was empty.

1
  • it worked for me! I've tried with too many command and nothing changed... but this was the solution for me! Feb 2, 2013 at 0:06
1

i fixed my problem....

not sure what the problem was but using the gitx interface to commit my staged files, then...

$ git push origin master

worked...

i am having the same problem...

created a new folder added in the bort template files...

$ git commit -m 'first commit'

$ git remote add origin [email protected]:eltonstewart/band-of-strangers.git

$ git push origin master

then i get the same error...

error: src refspec master does not match any.
fatal: The remote end hung up unexpectedly
error: failed to push some refs to '[email protected]:eltonstewart/band-of-strangers.git'

1
cd  app 

git init 

git status 

touch  test 

git add . 

git commit  -a  -m"message to log " 

git commit  -a  -m "message to log" 

git remote add origin 

 git remote add origin [email protected]:cherry 

git push origin master:refs/heads/master

git clone [email protected]:cherry test1
1

I had same issue. I had mistakenly created directory in machine in lower case. Once changed the case , the problem solved(but wasted my 1.5 hrs :( ) Check it out your directory name and remote repo name is same.

1

had the same issue a minute ago and then fixed it

create a repository in github called wordpress...

cd wordpress
git init
git add -A
git commit -am “WordPress 3.1.3″ or any message
git remote add origin [email protected]:{username}/wordpress.git
git push -u origin master

this should work to resolve the refspec issue

2
  • Thanks its working for me.. can i know what is the difference between "git add ." and "git add -A"
    – ROOT
    Dec 19, 2016 at 5:16
  • no difference if you are on v 2.x only matters if you are on 1.x check table for future ref: stackoverflow.com/a/26039014/640727 Dec 19, 2016 at 14:59
1

This can also happen because github has recently renamed the default branch from "master" to "main" ( https://github.com/github/renaming ), so if you just created a new repository on github use git push origin main instead of git push origin master

0

I mistankly put a space after the - so instead of -m I had - m Just something to look for.

0

I think in older version of git, you should commit at least one file first, and then you can "push origin master" once again.

0

great.. its the issue with empty directory only nothing else. I got my issue resolved by creating one binary file in each directory and then added them.

0

Initital add & commit worked like a charm. I guess it's just a matter of understanding Git's methodology of managing a project within the repository.

After that I've managed to push my data straight-away with no hassle.

0

I just encountered this problem, and it seemed to be caused by my not adding a custom commit message above the default commit message (I figured, why write "initial commit", when it clearly says that very same thing in the Git-generated text below it).

The problem resolved when I removed the .git directory, re-initialized the project directory for Git, re-added the GitHub remote, added all files to the new stage, committed with a personal message above the auto-generated message, and pushed to origin/master.

0

When you create a repository on Github, It adds a README.md file to the repo and since this file might not be there in your local directory, or perhaps it might have different content git push would fail. To solve the problem I did:

git pull origin master
git push origin master

This time it worked since I had the README.md file.

0

Before the first commit, try add some file like readme.txt. This will "force" the remote repo create the branch master in case that not exists. It's worked to me.

0

This is very old question but for all new people who will end up here like me. This solution is only for

error: src refspec master does not match any.

error for new repo created

You need to add your

git config user.email "your email"
git config user.name "name"

Only after adding email and name add files to git and commit

git add .
git commit -m "message"

It will work like charm

0

I have this error too, i put a commit for not push empty project like a lot of people do but doesn't work

The problem was the ssl, y put the next

git config --system http.sslverify false

And after that everything works fine :)

git push origin master

0

I was having same problem/error.I was doing git push -u origin master instead i just did git push origin master and it worked.

0

go to control panel -> manage your credentials and delete github credentials if any.

0

Bumping an old thread.

If you have created a repository on Github with a Readme or a .gitignore, you might have to rebase the local master with the remote master. Because, if you are using a project scaffolding tool, like create-app, it creates these files for you, and the remote master needs to be synced with your local before you push.

If you are creating an empty repository on Github, then you can simply push.

0

As some commented above, the problem could be that you do not have email and username or also in my case the problem was that I was trying to push the branch with a different email in the configuration, to check this:

  • git config --list

to modify it (globally):

-1

I had the same problem, some of the users have answered this. Before push you must have your first commit. Now for new users I've created a series of simple steps. Before that you need to install git and run in command line:

  • git config user.email "your email"
  • git config user.name "name"

The steps for creating a remote repository (I use dropbox as remote repository):

1. create a directory in Dropbox (or on your remote server)
2. go to the Dropbox dir (remote server dir)
3. type git command: git init --bare
4. on your local drive create your local directory
5. go to local directory
6. type git command: git init
7. add initial files, by typing git command:: git add <filename> 
8. type git command: git commit -a -m "initial version" (if you don't commit you can't do the initial push
9. type git command: git remote add name <path to Dropbox/remote server> 
10. git push name brach (for first commit the branch should be master)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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