header

Torsten Curdt’s weblog

From subversion to git (part1 - git)

You read it everywhere - obviously git must be the best since sliced bread. But replacing subversion with git is not exactly just as easy as one would hope. Installing git itself is simple. On Ubuntu just have to install the “git-core” package. But I would recommend some other packages as well.

apt-get install git-core git-svn gitweb

Done. You can already use git and push a git repository onto the server via ssh protocol. You would only need to expose the directory via http. If you want shared repository with permission administration you will need a slightly more complex setup. At least if you don’t want to hand out ssh account for every person. So I’d suggest you create your repository directory in the home directory of a separate “git” user

sudo adduser \
    --system \
    --shell /bin/sh \
    --gecos 'git version control' \
    --group \
    --disabled-password \
    --home /home/git \
    git
sudo -u git mkdir /home/git/repositories

Copy your public ssh key onto the machine as “/home/git/.ssh/authorized_keys” and you should be able to log into the machine with “ssh git@yourserver.com”.

In order to make the repositories available we now start the git daemon.

sudo -u git git-daemon
  --reuseaddr \
  --verbose \
  --base-path=/home/git/repositories/ \
  --detach

There is also a package called “git-daemon-run” to start the daemon on system start. Frankly speaking I found it way too complicated and just created a simple init.d script that does the trick.

sudo cat > /etc/init.d/git-daemon << EOF
#!/bin/sh

test -f /usr/bin/git-daemon || exit 0

. /lib/lsb/init-functions

GITDAEMON_OPTIONS="--reuseaddr --verbose --base-path=/home/git/repositories/ --detach"

case "$1" in
start)  log_daemon_msg "Starting git-daemon"

        start-stop-daemon --start -c git:git --quiet --background \
                     --exec /usr/bin/git-daemon -- ${GITDAEMON_OPTIONS}

        log_end_msg $?
        ;;
stop)   log_daemon_msg "Stopping git-daemon"

        start-stop-daemon --stop --quiet --name git-daemon

        log_end_msg $?
        ;;
*)      log_action_msg "Usage: /etc/init.d/git-daemon {start|stop}"
        exit 2
        ;;
esac
exit 0
EOF
update-rc.d git-daemon defaults

Once started you can create a new project

cd testproject
git init
git add .
git commit -m "initial import"
git remote add origin git@yourserver.com:repositories/testproject.git
touch .git/git-daemon-export-ok
scp -rp .git git@yourserver.com:repositories/testproject.git
git push --all

which pushes the initial project to the git server via ssh protocol. The “git-daemon-export-ok” makes it accessible to the outside world via git daemon. Now everyone can clone the repository which is the initial checkout and the first step to follow your work.

git clone git://yourserver.com/testproject.git

Now let’s also expose the git repository over http similar to viewvc

One Response to “From subversion to git (part1 - git)”

  1. Theome said, on 24. February 2008 at 15:33

    Hi

    I’ve tried your instructions but I cannot get the git repositoty working. I get an “unable to chdir or not a git archive” error

    When I look the logs, I see that git-daemon is unable to allocate the listen port. Do you have any idea why this happens?

Leave a Reply

Please copy the string g72eOM to the field below: