CentOS Stream 10

Git : Access to Repos via HTTP2026/07/08

 

Configure to access to Repos via HTTP.

[1]

Install Apache httpd, refer to here.

[2]

Configure SSL/TLS settings, refer to here (Optional).

[3] Configure Apache httpd to access to Git repositories.
For example, set [/var/www/git] as a root directory for Git repositories.
[root@dlp ~]#
vi /etc/httpd/conf.d/git.conf
# create new

SetEnv GIT_PROJECT_ROOT /var/www/git
SetEnv GIT_HTTP_EXPORT_ALL
ScriptAlias /git/ /usr/libexec/git-core/git-http-backend/

<Location /git>
    Options FollowSymLinks ExecCGI
    AuthName "Git for HTTP"
    AuthType Basic
    AuthUserFile /etc/httpd/conf/.htpasswd
    Require valid-user
</Location>

[root@dlp ~]#
systemctl reload httpd
# add user : create a new file with [-c]

[root@dlp ~]#
htpasswd -c /etc/httpd/conf/.htpasswd cent

New password:    
# set password

Re-type new password:
Adding password for user cent
[4] Create a Git repository under the root directory.
[root@dlp ~]#
mkdir /var/www/git

[root@dlp ~]#
cd /var/www/git

[root@dlp git]#
git init --bare project01.git

hint: Using 'master' as the name for the initial branch. This default branch name
hint: will change to "main" in Git 3.0. To configure the initial branch name
hint: to use in all of your new repositories, which will suppress this warning,
hint: 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>
hint:
hint: Disable this message with "git config set advice.defaultBranchName false"
Initialized empty Git repository in /var/www/git/project01.git/

[root@dlp git]#
chown -R apache project01.git
[5] If SELinux enabled, change policy.
[root@dlp ~]#
setsebool -P httpd_unified on
[6] Verify to access to a Git repository via HTTP.
[redhat@node01 ~]$
mkdir work

[redhat@node01 ~]$
cd work
# the user is you added with htpasswd on [3]

[redhat@node01 work]$
git clone https://cent@dlp.srv.world/git/project01.git

Cloning into 'project01'...
Password for 'https://cent@dlp.srv.world':   # password of the user in htpasswd
warning: You appear to have cloned an empty repository.

[redhat@node01 work]$
cd project01

[redhat@node01 project01]$
git config --global user.name "Server World"

[redhat@node01 project01]$
git config --global user.email "redhat@node01.srv.world"
[redhat@node01 project01]$
echo testfile > testfile1.txt

[redhat@node01 project01]$
git add testfile1.txt

[redhat@node01 project01]$
git commit testfile1.txt -m "Initial Commit"

[master (root-commit) 1435365] Initial Commit
 1 file changed, 1 insertion(+)
 create mode 100644 testfile1.txt

[cent@node01 project01]$
git remote -v

origin  https://cent@dlp.srv.world/git/project01.git (fetch)
origin  https://cent@dlp.srv.world/git/project01.git (push)

[redhat@node01 project01]$
git push origin master

Password for 'https://cent@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 (from 0)
To https://dlp.srv.world/git/project01.git
 * [new branch]      master -> master

[cent@node01 project01]$
git ls-files

testfile1.txt
Matched Content