Problem to publish project - GitHub

I am trying to publish a project on GitHub, but whenever I give a git push the message appears:

error: src refspec source does not match any.
error: failed to push some refs to 'https://github.com/user/project.git'

I've seen some solutions and none solved. Now this just started showing up, after I used GitHub for Windows, does it have anything to do with it?

 7
Author: DNick, 2014-06-12

3 answers

Hard to say with 100% certainty, but most likely the problem is that your local branch has a different name than the server branch (more precisely one of the two branches, the local or the remote, is not called master).

To be sure run the git show-ref Command (which lists the local references). A line should appear:

<algum SHA1>    refs/heads/master

And, just in case, also run git ls-remote (which lists remote referrals). A line with the same name should appear reference:

<algum SHA1>    refs/heads/master

would that be your problem?


Understanding...

The (more) complete syntax of the git push command is:

git push <nome do remoto> <nome do branch local>:refs/heads/<nome do branch remoto>

When you use the syntax (mentioned in the comments) git push origin master git takes master as both the local branch name and the remote name.

You can use different names for the two branches, for this you use the full form or you configure it in the file .git/config.

Se by Chance the simplified form is used without such a configuration the error message is exactly the one mentioned: "src refspec does not match any.". That is, the src part (the local branch) of the refspec (which is the name of such complete syntax with :) did not marry any other reference (does not match any). This "other reference" in the case is (implicitly) a reference from the remote (origin in your example).

In other words: the git tried to use the same name for the source and target branches but did not find branches on both sides with the given name.

 11
Author: talles, 2014-06-13 01:40:13

When we create an on-site project and apply the git init Command. Uma branch master it is created automatically.

When we create a new repository on GitHub . A branch is not automatically created master. So the git push origin master command does not roll. Why there is no branch master in the remote yet.

How to solve this problem? Create the first commit and then apply the git push. By custom I create the file .gitignore right after the command git init, as the following example:

touch .gitignore

git add .gitignore

git commit -m "gitignore file"

git push -u origin master
 1
Author: DNick, 2018-07-17 20:15:30

You must commit before pushing.

First add the files with the command:

git add .

Then commit:

git commit -m "primeiro commit"

Then push:

git push origin master

 0
Author: Rodrigo Gambarra, 2019-05-01 15:40:04