http経由でgitリポジトリを使えるようにする

Apacheのインストールはここ
gitのインストールはここ


サーバ側の準備

% sudo mkdir /opt/local/var/git
% sudo mkdir /opt/local/var/git/webFirstPj
% sudo cd /opt/local/var/git/webFirstPj
% sudo git --bare init
% sudo git update-server-info
% sudo sudo chmod -R 777 /opt/local/var/git/webFirstPj
% sudo vi /opt/local/apache2/conf/conf.d/git.conf
% sudo mkdir /opt/local/apache2/var
% htpasswd -c /opt/local/apache2/var/passwd.git {Basic認証のユーザ名}
% sudo /opt/local/apache2/bin/apachectl restart

クライアント 最初のコミットまでの流れ

% mkdir $HOME/git-test
% cd $HOME/git-test
% git clone http://{Basic認証のユーザ名}@localhost/git/webFirstPj
Cloning into webFirstPj...
Password: 
 →Basic認証のパスワードを入力
% cd $HOME/git-test/webFirstPj
% vi first.txt
% git add first.txt
% git commit
 →コメントを入力
% git push origin master
Password: 
Fetching remote heads...
  refs/
  refs/heads/
  refs/tags/
updating 'refs/heads/master'
  from 0000000000000000000000000000000000000000
  to   03a89a9fc49b2de181543de9bee1bbbf89b07147
    sending 3 objects
    done
Updating remote server info
To http://{Basic認証のユーザ名}@localhost/git/webFirstPj
 →PJにまだ何もコミットされていなかった空のリポジトリだった為、
  git push origin master という引数が必要。
  次回からはgit pushでOK。

conf.d/git.conf

DavLockDB "/tmp/DavLock"

Alias /git/webFirstPj/ "/opt/local/var/git/webFirstPj/"

<Directory "/opt/local/var/git/webFirstPj">
  DAV on
  AuthType Basic
  AuthName "Git"
  AuthUserFile /opt/local/apache2/var/passwd.git
  Require valid-user
  Order allow,deny
  Allow from all
</Directory>

※.netrcファイルを使えばURLにユーザ名を埋め込まないで実現できます。
※インターネットにリポジトリを公開するまでのセキュリティの考慮はしてません。