Git : HTTP でアクセスする2023/07/25 |
HTTP プロトコルで Git リポジトリにアクセスできるよう設定します。
|
|
[1] | |
[2] | |
[3] | Git リポジトリにアクセスできるよう Apache2 を設定します。 例として、Git リポジトリのルートディレクトリを [/var/lib/git] として設定します。 |
root@dlp:~#
vi /etc/apache2/conf-available/git.conf # 新規作成 SetEnv GIT_PROJECT_ROOT /var/lib/git SetEnv GIT_HTTP_EXPORT_ALL ScriptAlias /git/ /usr/lib/git-core/git-http-backend/ <Location /git> Options ExecCGI AuthName "Git for HTTP" AuthType Basic AuthUserFile /etc/apache2/.htpasswd Require valid-user </Location> a2enconf git root@dlp:~# a2enmod cgi rewrite
root@dlp:~#
systemctl restart apache2
# ユーザーを登録 : [-c] でファイルを新規作成する root@dlp:~# htpasswd -c /etc/apache2/.htpasswd debian New password: # パスワード設定 Re-type new password: Adding password for user debian |
[4] | 設定した Git リポジトリのルートディレクトリ配下に任意のリポジトリを作成しておきます。 |
root@dlp:~# cd /var/lib/git root@dlp:/var/lib/git# mkdir project01.git root@dlp:/var/lib/git# cd project01.git root@dlp:/var/lib/git/project01.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 /var/lib/git/project01.git/root@dlp:/var/lib/git/project01.git# chgrp -R www-data /var/lib/git/project01.git
|
[5] | 任意のノードから Git リポジトリに HTTP アクセスして動作確認します。 |
# htpasswd で登録したユーザーで認証 bookworm@node01:~/work$ git clone https://debian@dlp.srv.world/git/project01.git
Cloning into 'project01'...
Password for 'https://debian@dlp.srv.world': # htpasswd で登録したユーザーのパスワード
warning: You appear to have cloned an empty repository.
bookworm@node01:~/work$
bookworm@node01:~/work/project01$ cd project01 bookworm@node01:~/work/project01$ git config --global user.name "Server World" bookworm@node01:~/work/project01$ git config --global user.email "bookworm@node01.srv.world"
echo testfile > testfile1.txt bookworm@node01:~/work/project01$ git add testfile1.txt bookworm@node01:~/work/project01$ git commit testfile1.txt -m "Initial Commit" [master (root-commit) 9cf5686] Initial Commit 1 file changed, 1 insertion(+) create mode 100644 testfile1.txtbookworm@node01:~/work/project01$ git remote -v origin https://debian@dlp.srv.world/git/project01.git (fetch) origin https://debian@dlp.srv.world/git/project01.git (push)bookworm@node01:~/work/project01$ git push origin master Password for 'https://debian@dlp.srv.world': Enumerating objects: 3, done. Counting objects: 100% (3/3), done. Writing objects: 100% (3/3), 235 bytes | 235.00 KiB/s, done. Total 3 (delta 0), reused 0 (delta 0), pack-reused 0 To https://dlp.srv.world/git/project01.git * [new branch] master -> masterbookworm@node01:~/work/project01$ git ls-files testfile1.txt |
Sponsored Link |
|