Search code examples
gitgitolite

git, gitolite error push


I just installed gitolite but when I push on the repository gitolite-admin I get an error:

git push
Counting objects: 9, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (6/6), done.
Writing objects: 100% (7/7), 605 bytes, done.
Total 7 (delta 1), reused 0 (delta 0)
remote: Empty compile time value given to use lib at hooks/update line 6
remote: Use of uninitialized value in require at hooks/update line 7.
remote: Can't locate Gitolite/Hooks/Update.pm in @INC (@INC contains:  /etc/perl /usr/local/lib/perl/5.10.1 /usr/local/share/perl/5.10.1 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.10 /usr/share/perl/5.10 /usr/local/lib/site_perl .) at hooks/update line 7.
remote: BEGIN failed--compilation aborted at hooks/update line 7.
remote: error: hook declined to update refs/heads/master
To ssh://[email protected]/home/admin/repositories/gitolite-admin.git
! [remote rejected] master -> master (hook declined)
error: failed to push some refs to   'ssh://[email protected]/home/admin/repositories/gitolite-admin.git'

I don't know what I must do.

can you help me?

thanks


Solution

  • Before you start: The gitbox is the remote machine with git and gitolite installed. The git user is the user that gitolite runs as on the gitbox.

    You can overcome this error by (1) generating a new key pair, (2) registering the public key on the gitbox, and (3) by ensuring that when you connect to the gitbox, that you always connect as the git user using your new private key.

    For the ninja, that’s probably enough. For the rest, here’s more detail:

    Step 1) Generate a new keypair

    Most IDEs have the ability to create a new public/private keypair. Alternatively, if have access to a Linux machine you can generate your own using:

    ssh-keygen -t rsa -f john_git_rsa
    

    The output will be a set of private (john_git_rsa) and public (john_git_rsa.pub) keys (aka the keypair). You'll need to copy the public key to the gitbox in the next step.

    Step 2) Register new public key on gitbox

    You can find out how to use git to administer gitolite-admin with a quick search of Google. Briefly, the steps are: (1) clone the gitolite-admin repository; (2) add the new public key to the gitolite-admin/keydir/ directory; and (3) push the changes back to the gitolite-admin repository. The push triggers the gitbox to register any new keys in the keydir/ folder with the authorized users list of the gitbox's git user.

    Your gitbox is now ready to accept new connections from those authenticating as the git user, using the john_git_rsa private key.

    Step 3) Ensure your connections to the gitbox use the git user and new private key

    If you're connecting to the gitbox using terminal, edit/create the ~/.ssh/config file to include an alias that preconfigures your connection to the gitbox. The alias looks like:

    Host gitbox
       User git
       Hostname yourgitbox.com
       Port 22
       IdentityFile ~/.ssh/john_git_rsa
    

    Now, executing commands like >git clone gitbox:reponame.git, or >git push gitbox:reponame.git ensures you’re using the git user and appropriate private key. Without this alias, you'd have to do something like >git clone ssh://[email protected]:22/reponame.git and find out the ssh switch for specifying the private key to use – not pretty. (Note: If you connect without using this alias, your default ssh key will be used and you will receive permission errors.)

    OR if you use an IDE (NetBeans, Eclipse, etc.):

    You need to find your IDE's SSH settings and set them to use the new private key you created (john_git_rsa) instead of the default keys it generated during its install. You also need to ensure the URI of your push repository is set to something like:

    ssh://[email protected]:22/reponame.git
    

    that the username is set to git, and the password field is empty. This ensures that when you're connecting to the gitbox that your IDE will supply the private key you just setup and the git user.

    Now your pushes should work.