Setup Smart HTTP for Git + Gitweb in CentOS 7

I want my project url something like this:

So the clone command can be in this format: $ git clone

Create separate config file for Git: /etc/httpd/conf.d/git.conf

SetEnv GIT_PROJECT_ROOT /opt/git
ScriptAlias /git/ /usr/libexec/git-core/git-http-backend/

<LocationMatch "^/git/*">
AuthType Basic
AuthName "Git Access"
AuthUserFile /opt/git/.htpasswd
Require valid-user

Remember to grant permission: $ chown -R apache /opt/git

Create password for authentication: $ htpasswd /opt/git/.htpasswd andy

$ systemctl restart httpd

You can init a demo repository for testing:

$ cd /opt/git
$ mkdir myproject.git
$ cd myproject.git
$ git init --bare

$ git clone to test



Setup Gitweb:

$ yum install gitweb

  • The html resource: /var/www/git
  • The config file: /etc/gitweb.conf

Now we need to modify the config file to set project root:

our $projectroot = "/opt/git";

Start tracking existing project:
cd <localdir>
git init
git add .
git commit -m 'message'
git remote add origin <url>
git push -u origin master