Push origin master error on new repository

Viewed 231702

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 'git@github.com:{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 git@github.com:{username}/{projectname}.git
  git push origin master
29 Answers

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.

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

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 git@github.com: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 git@github.com:Odd-Engine

No more error! :)

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

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.

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 git@github.com: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 'git@github.com:eltonstewart/band-of-strangers.git'

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

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

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

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.

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

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.

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

  • git config --global user.email "email@email.com"
Related