git
リポジトリへHTTPS
経由でpull, pushできるようにする為の設定に関するメモ
gitに同梱されているgit-http-backend
というCGIを利用して、サーバー上に配置したリポジトリをリモートで接続する方法が用意されている。
Smart Httpに関する説明はこちら
まず、このgit-http-backendのありかだが、gitのインストール方法によっても違うが、/usr/lib/git-core/git-http-backendにインストールされていた。事前準備としては、Apacheでmod_env.so
が有効になってなければ有効にする。
LoadModule env_module modules/mod_env.so
https接続なので、virtual-ssl.conf
を編集し、サーバーを再起動する。
注意点としては、git-http-backendの後ろに必ず/
をつけること。
<ifmodule mod_ssl.c="">
<virtualhost _default_:443="">
:
SetEnv GIT_PROJECT_ROOT /var/git/repo
SetEnv GIT_HTTP_EXPORT_ALL
ScriptAlias /git/ /usr/lib/git-core/git-http-backend/
<location git="">
DAV on
AuthType Basic
AuthName "Authorization Realm"
AuthUserFile /etc/apache2/conf/userpass.passwd
Require valid-user
Order allow,deny
Allow from all
</location>
:
</virtualhost>
</ifmodule>
GIT_PROJECT_ROOT
で指定したディレクトリに移動し、その中にgitリポジトリ
を作成する。
また、chownでapache2の実行ユーザに変更しておく。
> cd /var/git/repo
> mkdir box.git
> git --bare init --shared=true
Initialized empty shared Git repository in /var/git/repo/box.git
> git update-server-info
> cd hooks
> cp post-update.sample post-update
> sudo chown -R www-data:www-data
動作するか確認する。デフォルト設定のままだと、SSH証明書をチェックするようになっている。オレオレ証明書で運用しているサーバーの場合、認証に失敗してしまうので、http.sslVerify
の値をfalse
に変更しておく。
空のboxリポジトリをcloneして、ファイルを登録して、pushしてみる。
> git config --global http.sslVerify false
>
> git clone https://www.usagi1975.com/git/box.git
Cloning into 'box'...
Username for 'https://www.usagi1975.com': hoge
Password for 'https://hoge@www.usagi1975.com': (password)
warning: You appear to have cloned an empty repository.
Checking connectivity... done.
> ls
box
> cd box
> echo hello > test.txt
> git add *
> git commit -m "test commit"
[master (root-commit) 193aa9f] test commit
1 file changed, 1 insertion(+)
create mode 100644 test.txt
> git push origin master
Username for 'https://www.usagi1975.com': hoge
Password for 'https://hoge@www.usagi1975.com': (password)
Counting objects: 3, done.
Writing objects: 100% (3/3), 213 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To https://www.usagi1975.com/git/box.git
* [new branch] master -> master
無事成功。