1

i'm trying to create a setup to push my local git repo to my web server, to later use post receive script to push changes from my website directly to the live website.

How i started:

  1. Downloaded Git (https://git-scm.com/download/win)
  2. Opend Git GUI and generated SSH key (without passphrase)
  3. Copied that to the ~/.ssh/authorized_keys file on my server from the user "myuser"
  4. connected with terminal to my server and done the following:
$ cd ~
$ mkdir example.com.git
$ cd ~/example.com.git
$ git init --bare
$ exit
  1. created local a folder on my desktop
  2. opened git bash there
  3. entered the following commands:
$ git config --global user.name "My Name"
$ git config --global user.email my@email.com
$ git init
$ git add .
$ git commit -m "First Commit"
  1. Then i added the remote
git remote add scoutsofnature ssh://myuser@server.domain.tld/~/example.com.git
  1. When i tried to git push with:
git push -u scoutsofnature master

it fails with following error:

error: src refspec master does not match any
error: failed to push some refs to  'ssh://server.domain.tld:PORTNUMBER/~/example.com.git'

I'm likely new to git so would be nice if somebody can explain where i failed.

That are my references:

Best regards

torek
  • 448,244
  • 59
  • 642
  • 775
yFStein
  • 29
  • 7
  • I'm sure there were more error lines after `git push`. Can we see all of them? – phd May 18 '21 at 10:41
  • `$ git push -u scoutsofnature master ` `error: src refspec master does not match any ` `error: failed to push some refs to 'ssh://server.domain.tld:PORTNUMBER/~/example.com.git' ` thats all – yFStein May 18 '21 at 10:53
  • https://stackoverflow.com/a/67545863/7976758 Found in https://stackoverflow.com/search?q=%5Bgit%5D+error%3A+src+refspec+master+does+not+match+any – phd May 18 '21 at 10:54
  • same error when `$ git push -u scoutsofnature main` – yFStein May 18 '21 at 11:01
  • `git status`? `git branch`? `git log`? Did `git commit` create any commit? I suspect it didn't because the directory is empty and `git add` didn't add anything. – phd May 18 '21 at 11:30

2 Answers2

0

Just to test, try and replace ~ with the actual full path on your server.
For instance:

git remote set-url scoutsofnature ssh://myuser@server.domain.tld/home/myuser/example.com.git

Then, as commented, check your git status/git branch -avv to make sure you are pushing the right branch.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
0

The real error here is in the first line (I edited your comment into the question); the second error: line is just a summary of the previous error(s). The first line here is:

error: src refspec master does not match any

which means quite simply that you don't have a master branch.

What we don't know if why you don't have a master branch, but many people have started using main as their initial and/or primary branch name. Perhaps you have a main branch and should be using that name everywhere.

It's important to realize that every Git clone has its own set of branch names. Your own repository may be using branches named zorg and palpatine1 while some other related repository uses names like leeloo and leia for the same purposes. It's pretty standard for us humans to want to, and therefore to actually do, use the same names in different repositories, but Git doesn't really care. Git only uses the names to find commit hash IDs. You are allowed to use different names on the two "sides" of a fetch or push operation.

Hence, you need to:

  • find / decide on the names you want to use in your repository;
  • find / decide on the names others want to use in their repositories; and
  • use the appropriate kind of git fetch and/or git push operations to manage these.

For instance, if you want to use gruber to keep track of the main branch, while they're using mcclane for theirs, you might use:

git push diehard gruber:mcclane

to send your new main-branch commit to their main-branch.


1I was tempted to go back and swap out the Star Wars references for another Bruce Willis movie, but didn't get around to it. Maybe Mr Glass from Unbreakable?

torek
  • 448,244
  • 59
  • 642
  • 775