Git error: src refspec master does not match any [

2019-01-16 02:34发布

This question already has an answer here:

I need to create a repo named carboncake.

I tried this:

Cloned the gitosis-admin repository to my local machine

$ git clone gitosis@myserver.net:repositories/gitosis-admin.git
$ cd gitosis-admin
$ vim gitosis.conf

Added the [repo carboncake] and [group carboncake] section to the end of the file

[gitosis]

[group team]
writable = sweepshots
members = git_id_rsa

[group gitosis-admin]
writable = gitosis-admin
members = git_id_rsa

[repo carboncake]
description = A brand new app by Mithun.
owner = Mithun P

[group carboncake]
writable = myappname
members = mithun @core

Then copied the pub key file generated by Putty (I'm using Git basg for Windows):

$cp /some/where/mithun.pub keydir/mithun.pub

Executed the following commands:

$ git add gitosis.conf keydir/mithun.pub
$ git commit -m "Added 'carboncake' repository and 'mithun' user."

$ git pull --rebase
$ git push

But it doesn't create any carboncake.git in My Server.

So I followed this:

Executed the following commands on the server:

$ su gitosis 
$ git init --bare /srv/gitosis/repositories/carboncake.git

Here's my problem:

I tried to checkout/clone the new repository from my local machine

$ mkdir carboncake
$ cd carboncake
$ git init 
$ touch a_text_file.txt 
$ git add a_text_file.txt 
$ git remote add origin gitosis@myserver.net:repositories/carboncake.git
$ git push origin master

Which returned the error:

error: src refspec master does not match any.
fatal: The remote end hung up unexpectedly
error: failed to push some refs to 'gitosis@myserver.net:repositories/carboncake.git'

When I tried git push origin HEAD:master it returned the error:

error: src refspec HEAD does not match any.
fatal: The remote end hung up unexpectedly
error: failed to push some refs to 'gitosis@myserver.net:repositories/carboncake.git'

When I tried git push origin master:refs/heads/master it returned the error:

error: src refspec master does not match any.
fatal: The remote end hung up unexpectedly
error: failed to push some refs to 'gitosis@myserver.net:repositories/carboncake.git'

git show-ref on the local machine does not display anything

Also /srv/gitosis/repositories/carboncake.git/refs/heads/ directory on the server is empty.

How can I fix this?

2条回答
三岁会撩人
2楼-- · 2019-01-16 03:01

You've created a new repository and added some files to the index, but you haven't created your first commit yet. After you've done:

 git add a_text_file.txt 

... do:

 git commit -m "Initial commit."

... and those errors should go away.

查看更多
冷血范
3楼-- · 2019-01-16 03:02

The quick possible answer: When you first successfully clone an empty git repository, the origin has no master branch. So the first time you have a commit to push you must do:

git push origin master

Which will create this new master branch for you. Little things like this are very confusing with git.

If this didn't fix your issue then it's probably a gitolite-related issue:

Your conf file looks strange. There should have been an example conf file that came with your gitolite. Mine looks like this:

repo    phonegap                                                                                                                                                                           
    RW+     =   myusername otherusername                                                                                                                                               

repo    gitolite-admin                                                                                                                                                                         
    RW+     =   myusername                                                                                                                                                               

Please make sure you're setting your conf file correctly.

Gitolite actually replaces the gitolite user's account with a modified shell that doesn't accept interactive terminal sessions. You can see if gitolite is working by trying to ssh into your box using the gitolite user account. If it knows who you are it will say something like "Hi XYZ, you have access to the following repositories: X, Y, Z" and then close the connection. If it doesn't know you, it will just close the connection.

Lastly, after your first git push failed on your local machine you should never resort to creating the repo manually on the server. We need to know why your git push failed initially. You can cause yourself and gitolite more confusion when you don't use gitolite exclusively once you've set it up.

查看更多
登录 后发表回答