Categories
How-to

Switch to self-hosted private git easily

Don’t like plans on github or had enough with downtimes on services like that, it’s not enough space provided by git hosting service? No problem! Switch to self-hosted git then, it’s quick and easy, you will still be able to track changes etc in console or via GUI of your git client, or you can even setup gitweb/instaweb to have web-interface. Personally, I don’t like any git hosting service because they’re not reliable and don’t provide enough space and private repos.

So what you need is gitolite – easy to use, well-documented git server managing system via git itself. You can read installation instructions and installation transcript first or just start from below if you feel you’re lucky.

If you’re setting up git on your server obviously you have root access (i will list instructions on this way only, you can find other types of installations.

Copy ~/.ssh/id_rsa.pub from your workstation (or create new one), copy your file to the server. Put it in /tmp/Your_Name.pub.

cd ~
git clone git://github.com/sitaramc/gitolite gitolite-source
cd gitolite-source

Now checkout whatever branch you want, by default it should checkout “pu” branch, or do “git checkout -t origin/pu” if you have another one.

mkdir -p /usr/local/share/gitolite/conf /usr/local/share/gitolite/hooks
src/gl-system-install /usr/local/bin /usr/local/share/gitolite/conf /usr/local/share/gitolite/hooks

Switch to git user:

su - git

if you have su: user git does not exist, you need to add git user to the system then run the command above again:

useradd git
passwd git

Now run:

which gl-setup

This should respond with /usr/local/bin/gl-setup. If this is not what you get, you have some $PATH issues. Make sure /usr/local/bin is in the $PATH for the git user, and that no prior components of the path contain another copy of gl-setup. You must run the one in the directory that is the first argument of gl-system-install above.

Now run setup script and pass it your key:

gl-setup /tmp/YourName.pub

Set up process finishes here. Now clone gitonlite settings repo on your client:

cd
git clone git@server:gitolite-admin

You can find repos setting file in /conf/gitonline.conf:

repo    gitolite-admin
        RW+     =   YourName

repo    testing
        RW+     =   @all

To add new repo, simply add this lines to that file and commit/push on this repo (you will see server response about initializing new repo:

repo    newrepo
        RW+     =   YourName

If you want to add more users, you need to paste key file to /keydir/ with the same username (/keydir/AnotherUser.pub) as you’re adding to repo (AnotherUser for example):

repo    newrepo
        RW+     =   YourName
        RW+     =   AnotherUser

If you want to migrate yout github repos to gitonline, heres a script that helps to do it:

#!/bin/bash

githubuser=your_github_username
gitonlinehost=your_gitonlite_server_hostname
repos=( repo1 repo2 repo3 )

for repo in ${repos[@]}
do
echo $repo
git clone --bare [email protected]:$githubuser/$repo
cd $repo.git
git push --mirror git@gitonlinehost:$repo.git
cd ..
rm -fr $repo.git
done

‘repos’ contain the names of the repos to be migrated. Note that collaborators, comments and anything outside of git itself will not be migrated!

Leave a Reply

Your email address will not be published. Required fields are marked *