Macでgit環境を構築

mercurialで頑張っていましたが、いよいよ下火になってきた気がしたのでgitに移行してみました。
構築がすごくめんどくさかったのでメモ。
mercurial楽だったんだけどなぁ。
サーバもクライアントもMacです。
macportsをフル活用します。

サーバ

git-coreをインストール。

# sudo port install git-core +gitweb

Apache2がインストール済みという想定で書きます。
また、mod_davもインストール済みとします。

  • /usr/local/apache2/conf/httpd.conf

LoadModule dav_module modules/mod_dav.so


で、mod_davが有効になっているか確認。
git用のApache設定。
httpdに設定するか、conf.dなどに設定するかは各環境で。

Alias /git/ /var/local/www/git/

Dav on
Order deny,allow
Allow from all
AuthType Basic
AuthName "git"
AuthUserFile "/usr/local/apache2/conf/git.passwd"
Require valid-user


Alias /gitweb /var/local/www/cgi-bin/gitweb

AddHandler cgi-script .cgi
Options Indexes MultiViews ExecCGI
AuthType Basic
AuthName "git"
AuthUserFile "/usr/local/apache2/conf/git.passwd"
Require valid-user


gitwebを上で指定したディレクトリにコピーします。

# cp -pr /opt/local/share/git-core/gitweb /var/local/www/cgi-bin/


これで、Apacheを再起動してみてエラーが出なければOK。


サーバに空っぽのリポジトリを作っておきます。

# cd /var/local/www
# mkdir git
# cd git
# git --bare init

クライアント

curlsslオプション付きでインストールします。
これは、httpsでPushできるようにするため。

# sudo port -d install curl +ssl

次に、git-coreをインストールしますが、git-coreのProfileに細工が必要です。

  • /opt/local/var/macports/sources/rsync.macports.org/release/ports/devel/git-core/Portfile

patchfiles patch-Makefile.diff patch-http.h.diff

patchfiles patch-Makefile.diff


この修正をしたら、

sudo port install -d git-core +svn


Basic認証のユーザアカウント設定。

  • ~/.netrc

machine www.example.com login neko password nya


パーミッションを忘れずに変えましょう。

# chmod 600 ~/.netrc


これで環境構築はOK。
使い方はまだよく理解できていません。

# git init

  • ファイルの追加とコミット

# git add somefile
# git commit -m "description"

# git clone http://www.example.com/git/

  • リモートリポジトリの追加(あまり使わない)

# git remote add origin http://www.example.com/git/

# git push

# git pull

  • ブランチの作成

# git branch somebranch

  • タグの作成

# git tag sometag

  • ブランチとHEADのマージ

# git merge somebranch

とりあえずこれぐらいから始めれば徐々に使いこなせそう。
SVKとさほど差はないので困ることはなさそうだが。
やっぱりmercurialじゃなくて、gitが流行る理由がわからないなぁ。