Upgrading to Gitolite from Gitosis

Git

I have been using git as source control for all of my projects for a little while now. Now that I am getting used to git, I like it a lot. It’s a bit of a different style than other source control management systems, but it seems to work well. I am starting to store lots of things in source control. Not only my programming projects, but also my random helper scripts and configuration files that I write. Basically, anything where in the past I would simply rename the file to “File.old”, it makes more sense to add it to source control instead. That way I can go back as many versions as I need to (without having an .oldX) and also see exactly what I have changed.

Gitosis vs Gitolite

I started off using Gitosis for repository management on my server. I wanted to be able to clone repositories and commit updates easily. While Gitosis works; I have decided that I want to migrate to Gitolite for a few reasons:

  • Gitolite is still being maintained — Gitosis is not
  • Better user management of repositories. Allow different users different access. I.E. I can do everything, but a friend is unable to delete files permanently.
  • Multiple keys per user. I have a few different machines that I develop on, and each machine has its own ssh key. Gitolite allows a nice format where one user can have multiple keys without cluttering up the config file.
  • I don’t like how I have to use MyRepository.git when cloning with Gitosis. Gitolite allows simply a clone of MyRepository.
  • Easier to create new repositories.

Migration

I followed the guide on the Gitolite site: http://sitaramc.github.com/gitolite/doc/migrate.html

And, I used this one to install Gitolite: http://sitaramc.github.com/gitolite/doc/1-INSTALL.html#_root_method_directly_on_the_server_manually_with_root_access

Both guides are pretty accurate.

This was the only issue I found in the migration guide:

src/gl-conf-convert < $GSAC/gitosis.conf >> $GLAC/gitolite.conf

should be

src/gl-conf-convert < $GSAC/gitosis.conf >> $GLAC/conf/gitolite.conf

Using Gitolite

Once Gitolite is installed, creating new repositories becomes easy (A lot easier than Gitosis seemed to make it).

Get your gitolite-admin repository (this should have already been done in the install phase)

git clone ssh://git@SERVER:gitolite-admin

Edit gitolite-admin/conf/gitolite.conf and add a repository:

repo scripts
RW+ = YourGitoliteUserHere
R = daemon

The R = daemon allows for public read access to this repository (see Git-Daemon Below)

Then, simply save commit and push your changes.

git commit -am "Added new scripts repository"
git push

You now have an empty repository with which to do your bidding.

git clone ssh://git@SERVER:scripts

or for git-daemon read only:
Notice the “/repoName” syntax instead of the normal “:repoName”

git clone git://SERVER/scripts

Git-Daemon

I wanted to allow public access to some of my repositories. Git-daemon is the perfect way to do this. And, gitolite supports allowing certain repositories access with git-daemon.

To get git-daemon working, I created a git-daemon service file:

# Taken from here: http://pastie.org/227647
#Really from here: https://help.ubuntu.com/community/Git

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
NAME=git-daemon
PIDFILE=/var/run/$NAME.pid
DESC="the git daemon"
DAEMON_USER=git
DAEMON_BASEPATH=/home/git/repositories
DAEMON=/usr/lib/git-core/git-daemon
DAEMON_OPTS="--base-path=$DAEMON_BASEPATH --verbose --syslog --detach --pid-file=$PIDFILE --user=$DAEMON_USER --group=nogroup"

test -x $DAEMON || exit 0

[ -r /etc/default/git-daemon ] && . /etc/default/git-daemon

. /lib/lsb/init-functions

start_git() {
start-stop-daemon --start --quiet --pidfile $PIDFILE \
--startas $DAEMON -- $DAEMON_OPTS
}

stop_git() {
start-stop-daemon --stop --quiet --pidfile $PIDFILE
rm -f $PIDFILE
}

status_git() {
start-stop-daemon --stop --test --quiet --pidfile $PIDFILE >/dev/null 2>&1
}

case "$1" in
start)
log_begin_msg "Starting $DESC"
start_git
log_end_msg 0
;;
stop)
log_begin_msg "Stopping $DESC"
stop_git
log_end_msg 0
;;
status)
log_begin_msg "Testing $DESC: "
if status_git
then
log_success_msg "Running"
exit 0
else
log_failure_msg "Not running"
exit 1
fi
;;
restart|force-reload)
log_begin_msg "Restarting $DESC"
stop_git
sleep 1
start_git
log_end_msg 0
;;
*)
echo "Usage: $0 {start|stop|restart|force-reload|status}" >&2
exit 1
;;
esac

exit 0

The only things that really needs to be modified are the DAEMON* lines (Lines 8-11).
DAEMON_USER= Your gitolite user name. This is typically “git” or “gitolite”
DAEMON_BASEPATH= Where your Gitolite repositories are stored.
DAEMON= Where the git-daemon binary is stored
DAEMON_OPTS= Any extra options that should be passed to the daemon

You will need to make the script executable.

sudo chmod +x /etc/init.d/git-daemon

Now you can control the git-daemon service:

sudo /etc/init.d/git-daemon start
sudo /etc/init.d/git-daemon stop
sudo /etc/init.d/git-daemon restart
sudo /etc/init.d/git-daemon status

If you want git-daemon to start automatically at boot, you can run this (Ubuntu only):

sudo update-rc.d git-daemon defaults

Now any repository with a user “daemon” setup for read access (git-daemon only allows read-only). is publicly available using the git:// protocol (assuming the git port 9418 is forwarded to your git server)

git clone git://llamabyte.com/testing

Write a Comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>