Git error: src refspec master does not match any

Mithun Sreedharan picture Mithun Sreedharan · Apr 27, 2011 · Viewed 312.4k times · Source

I need to create a repo named carboncake.

I tried this:

Cloned the gitosis-admin repository to my local machine

$ git clone [email protected]: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 [email protected]: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 '[email protected]: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 '[email protected]: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 '[email protected]: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?

Answer

Mark Longair picture Mark Longair · Apr 27, 2011

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.