Problem to publish project - Github

Asked

Viewed 19,214 times

7

I’m trying to publish a project on Github, but every time I give a git push 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 them. Now this only started to appear, after I used Github for Windows, has something to do?

6 answers

11


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 to execute the command git show-ref (which lists local references). A line should appear:

<algum SHA1>    refs/heads/master

And just in case, do it too git ls-remote (which lists remote reffers). A line with the same reference name should appear:

<algum SHA1>    refs/heads/master

Would that be your problem?


Understanding...

The complete (plus) syntax of the command git push 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 over master as both the local branch name and the remote name.

It is possible to use different names for the two branches, to do this the complete form is used or configured in the file .git/config.

If by chance the simplified form is used without such configuration the error message is exactly the mentioned: "src refspec does not any match.". That is, the part src (the local branch) of refspec (which is the name of such a syntax complete with :) married no other reference (does not any match). This "other reference" in the case is (implicitly) a remote reference (origin in his case).

In other words: git tried to use the same name for the source and destination branches but did not find two-sided branches with the given name.

2

When we create a project on-site and apply the command git init. One branch master is automatically created.

When we create a new repository on github. Does not automatically create a branch master. That’s why the command git push origin master doesn’t happen. Why isn’t there a branch master still remote.

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 an example below:

touch .gitignore

git add .gitignore

git commit -m "gitignore file"

git push -u origin master
  • Solved my problem. Thank you very much!

0

I was having the same problem for a short time. The problem was that the branch was under a different name. When I corrected the name, it was.

Could be the case here.

error: src refspec main does not match any

git itself says the problem, if it did not match... it has a 70% chance of being different naming between the remote repository and the local.

Fim do erro após renomear a branch

0

You must commit before pushing.

First add the files with the command:

git add .

Then commit:

git commit -m "primeiro commit"

Then the push:

git push origin master

-1

First see if the git settings are filled, I was having the same problem sending the files to my repository

Open your git Bash and type

git config --list

inserir a descrição da imagem aqui

and see if the variables user name.= and user email.= are filled

if you are not in trouble with these commands

git config --global user.name 'SEU NOME'

and then

git config --global user.email 'SEU E-MAIL'

inserir a descrição da imagem aqui

In my case that the error did not appear mai just follow up with the upload

example:

git commit -m "first commit"
git branch -M main
git remote add origin https://github.com/FernandoSena/teste.git
git push -u origin main

-2

Some changes were made to Github, maybe your name is main, so the command is:

git push origin main

With this solution has been solved my problem, I hope you help someone

Browser other questions tagged

You are not signed in. Login or sign up in order to post.