Git : Access to Repos via HTTP2024/07/24 |
Configure to access to Repos via HTTP. |
|
[1] | |
[2] | |
[3] | Configure Apache2 to access to Git repositories. For example, set [/var/lib/git] as a root directory for Git repositories. |
root@dlp:~#
vi /etc/apache2/conf-available/git.conf # create new 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
# add user : create a new file with [-c] root@dlp:~# htpasswd -c /etc/apache2/.htpasswd ubuntu New password: # set password Re-type new password: Adding password for user ubuntu |
[4] | Create a Git repository under the root directory. |
root@dlp:~# cd /var/lib/git root@dlp:/var/lib/git# mkdir project02.git root@dlp:/var/lib/git# cd project02.git root@dlp:/var/lib/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 /var/lib/git/project02.git/root@dlp:/var/lib/git/project02.git# chown -R www-data:www-data /var/lib/git/project02.git
|
[5] | Verify to access to a Git repository via HTTP. |
# the user is you added with htpasswd on [3] noble@node01:~/work$ git clone https://ubuntu@dlp.srv.world/git/project02.git Cloning into 'project02'... Password for 'https://ubuntu@dlp.srv.world': warning: You appear to have cloned an empty repository.
noble@node01:~/work$
noble@node01:~/work/project02$ cd project02 noble@node01:~/work/project02$ git config --global user.name "Server World" noble@node01:~/work/project02$ git config --global user.email "noble@node01.srv.world"
echo testfile > testfile1.txt noble@node01:~/work/project02$ git add testfile1.txt noble@node01:~/work/project02$ git commit testfile1.txt -m "Initial Commit" [master (root-commit) 1587a80] Initial Commit 1 file changed, 1 insertion(+) create mode 100644 testfile1.txtnoble@node01:~/work/project02$ git remote -v origin https://ubuntu@dlp.srv.world/git/project02.git (fetch) origin https://ubuntu@dlp.srv.world/git/project02.git (push)noble@node01:~/work/project02$ git push origin master Password for 'https://ubuntu@dlp.srv.world': Enumerating objects: 3, done. Counting objects: 100% (3/3), done. Writing objects: 100% (3/3), 233 bytes | 233.00 KiB/s, done. Total 3 (delta 0), reused 0 (delta 0), pack-reused 0 To https://dlp.srv.world/git/project02.git * [new branch] master -> masternoble@node01:~/work/project02$ git ls-files testfile1.txt |
Sponsored Link |