While local git is fine for personal development, sometimes you want to make stuff happen on a remote machine, either to share or for backup. SSH works well for this. However, I am going to target hosting my Git repository in an OpenShift instance, and HTTPS will be a much easier protocol to support.
Git-core comes with a CGI binary called git-http-backend. I used the following config file for Apache to expose it to the world (don’t use this yet…see below before you go on and run with it):
<VirtualHost *:80> SetEnv GIT_PROJECT_ROOT /var/www/git SetEnv GIT_HTTP_EXPORT_ALL DocumentRoot /var/www/git ScriptAlias / /usr/libexec/git-core/git-http-backend/ <Directory "/usr/libexec/git-core"> Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch AllowOverride None Require all granted </Directory> <Directory "/var/www/git"> Dav On Options Indexes FollowSymLinks AllowOverride None Require all granted </Directory> </VirtualHost> |
I was able to follow the approach here: https://linuxhint.com/git_server_http_centos8/ For Fedora as well. The script posted there works to create a subdirectory as a git repo under /var/www/git.
To make SELinux happy, I had to run:
sudo chcon -R -t httpd_sys_rw_content_t /var/www/git |
With that, I can clone to and from my local machine.
When I run a service like git, I’d like to be able to point a browser at it and see the changes. But the Git implementation of the HTTP protocol is made for for machine access, not human. To browse the repos, I can run the gitweb CGI service along with the git-http-backend. Fedora and RHEL package Gitweb in its own RPM. I can yum install that and run it by default. It stakes a couple of claims: the git repos should be stored on the local disk at /var/lib/git, and the Web service runs as the suburl of http://hostname/git. THus, I can change the git.conf file to look like this:
<VirtualHost *:80> SetEnv GIT_PROJECT_ROOT /var/lib/git SetEnv GIT_HTTP_EXPORT_ALL DocumentRoot /var/lib/git ScriptAlias /repo /usr/libexec/git-core/git-http-backend/ <Directory "/usr/libexec/git-core"> Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch AllowOverride None Require all granted </Directory> <Directory "/var/lib/git"> Dav On Options Indexes FollowSymLinks AllowOverride None Require all granted </Directory> </VirtualHost> |
With the file specified this way, I can clone like this:
git clone http |
And browse the repositories using http://gitserver/git/