Git : HTTP でアクセスする2024/09/13 |
HTTP プロトコルで Git リポジトリにアクセスできるよう設定します。 |
|
[1] | |
[2] | |
[3] | Git リポジトリにアクセスできるよう Apache httpd を設定します。 例として、Git リポジトリのルートディレクトリを [/usr/local/git] として設定します。 |
root@dlp:~ #
vi /usr/local/etc/apache24/httpd.conf <IfModule !mpm_prefork_module> # 166行目 : [prefork] 以外で起動の場合はこちらをコメント解除 LoadModule cgid_module libexec/apache24/mod_cgid.so </IfModule> <IfModule mpm_prefork_module> # 169行目 : [prefork] で起動の場合はこちらをコメント解除 #LoadModule cgi_module libexec/apache24/mod_cgi.so </IfModule> # 181行目 : コメント解除 LoadModule rewrite_module libexec/apache24/mod_rewrite.so
root@dlp:~ #
vi /usr/local/etc/apache24/Includes/git.conf # 新規作成 SetEnv GIT_PROJECT_ROOT /usr/local/git SetEnv GIT_HTTP_EXPORT_ALL ScriptAlias /git /usr/local/libexec/git-core/git-http-backend <Location /git> Options ExecCGI AuthName "Git for HTTP" AuthType Basic AuthUserFile /usr/local/etc/apache24/.htpasswd Require valid-user </Location>
root@dlp:~ #
service apache24 restart
# ユーザーを登録 : [-c] でファイルを新規作成する root@dlp:~ # htpasswd -c /usr/local/etc/apache24/.htpasswd freebsd New password: # パスワード設定 Re-type new password: Adding password for user freebsd |
[4] | 設定した Git リポジトリのルートディレクトリ配下に任意のリポジトリを作成しておきます。 |
root@dlp:~ # cd /usr/local/git root@dlp:/usr/local/git # mkdir project02.git root@dlp:/usr/local/git # cd project02.git root@dlp:/usr/local/git/project02.git # git init --bare --shared hint: Using 'master' as the name for the initial branch. This default branch name hint: is subject to change. To configure the initial branch name to use in all hint: of your new repositories, which will suppress this warning, call: hint: hint: git config --global init.defaultBranch <name> hint: hint: Names commonly chosen instead of 'master' are 'main', 'trunk' and hint: 'development'. The just-created branch can be renamed via this command: hint: hint: git branch -m <name> Initialized empty shared Git repository in /usr/local/git/project02.git/root@dlp:/usr/local/git/project02.git # chown -R www:www /usr/local/git/project02.git
|
[5] | 任意のノードから Git リポジトリに HTTP アクセスして動作確認します。 |
serverworld@node01:~ $
mkdir work serverworld@node01:~ $ cd work
# htpasswd で登録したユーザーで認証 serverworld@node01:~/work $ git clone https://freebsd@dlp.srv.world/git/project02.git Cloning into 'project02'... Password for 'https://freebsd@dlp.srv.world': warning: You appear to have cloned an empty repository.
serverworld@node01:~/work $
serverworld@node01:~/work/project02 $ cd project02 serverworld@node01:~/work/project02 $ git config --global user.name "Server World" serverworld@node01:~/work/project02 $ git config --global user.email "serverworld@node01.srv.world"
echo testfile > testfile1.txt serverworld@node01:~/work/project02 $ git add testfile1.txt serverworld@node01:~/work/project02 $ git commit testfile1.txt -m "Initial Commit" [master (root-commit) 49af1a1] Initial Commit 1 file changed, 1 insertion(+) create mode 100644 testfile1.txtserverworld@node01:~/work/project02 $ git remote -v origin https://freebsd@dlp.srv.world/git/project02.git (fetch) origin https://freebsd@dlp.srv.world/git/project02.git (push)serverworld@node01:~/work/project02 $ git push origin master Password for 'https://freebsd@dlp.srv.world': Enumerating objects: 3, done. Counting objects: 100% (3/3), done. Writing objects: 100% (3/3), 234 bytes | 234.00 KiB/s, done. Total 3 (delta 0), reused 0 (delta 0), pack-reused 0 (from 0) To https://dlp.srv.world/git/project02.git * [new branch] master -> masterserverworld@node01:~/work/project02 $ git ls-files testfile1.txt |
Sponsored Link |