[git] Push origin master error on new repository

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

This question is related to git github

The answer is


I have same issue . it's solved my problem . If 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


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.


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


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.


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


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.


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)

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


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.


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


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.


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'


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

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.


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

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.


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)


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

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.


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.


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


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.


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


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


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.


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


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