267

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?

CharlesB
  • 86,532
  • 28
  • 194
  • 218
Mithun Sreedharan
  • 49,883
  • 70
  • 181
  • 236
  • To those getting here from Google, you may just need to update git. Having an outdated version can occasionally cause weird errors when you're trying to push your changes. – Pikamander2 Jul 01 '18 at 11:41
  • One trivial mistake here is "git push origin master" versus "git push origin main" ... – Fattie Mar 17 '21 at 17:17

2 Answers2

616

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.

Mark Longair
  • 446,582
  • 72
  • 411
  • 327
  • 6
    @Danny [Just made a new repository for the first time in a few months...](https://www.youtube.com/watch?v=t2F1rFmyQmY) – yurisich May 12 '13 at 22:12
  • 121
    `git` has some awful error messages. – Justin Skiles Mar 04 '14 at 03:43
  • Absolutely right, it just happened to me with the same error message and realized i havent dont staging and committing. This means i have just upvoted this, one up. – blakroku Mar 30 '15 at 10:40
  • 2
    did not help in my case at all unfortunatelly. After the steps, I get another error fatal: Unable to create 'C:/Users/myname/Desktop/work/xamarin/myproj-vs2015/.git/index.lock': File exists. This is followed by "Another git process seems to be running in this repository, e.g. an editor opened by 'git commit'. Please make sure all processes are terminated then try again. If it still fails, a git process may have crashed in this repository earlier: remove the file manually to continue." I dont have any other process and I have tried deleting the .git and .git/index.lock file few times. – pixel Nov 08 '16 at 22:07
  • I already had a commit and still got that error. 'git push origin' (write nothing else) worked for me. – Ismael Rivera Feb 14 '19 at 03:12
  • 5
    try `git branch "branch-name" first` – Mohammad Mahdi KouchakYazdi Oct 28 '19 at 10:29
25

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.

Mauvis Ledford
  • 40,827
  • 17
  • 81
  • 86