簡易gitサーバの立ち上げ

smart HTTPという技術を用いるのがいいようだ。

CentOSの場合、リポジトリファイルやパスワードファイルは/var/www以下になければならないようだ。

1. サーバ側
cd /var/www
mkdir git
cd git
mkdir TmpRepos
cd TmpRepos
git init --bare --shared
git update-server-info
cd ..
chown -R apache.apache git
htpasswd -c /var/www/git/passwd_git git

/etc/httpd/conf/httpd.confの最後に以下を追加:

SetEnv GIT_PROJECT_ROOT /var/www/git
SetEnv GIT_HTTP_EXPORT_ALL
ScriptAlias /git/ /usr/libexec/git-core/git-http-backend/

<LocationMatch "/git">
        Order allow,deny
        Allow from All
        AuthName "Git"
        AuthType Basic
        AuthUserFile /var/www/git/passwd_git
        Require valid-user
</LocationMatch>

ウェブサービスの再起動:
/etc/rc.d/init.d/httpd restart

2. クライアント側

GIT_CURL_VERBOSE=1 git clone http://servername.jp/git/TmpRepos
最後にスラッシュ(/)を付けたら、エラーになったので、注意。