Setup Smart HTTP for Git + Gitweb in CentOS 7

I want my project url something like this: https://www.yianzhou.com/git/project.git

So the clone command can be in this format: $ git clone https://www.yianzhou.com/git/project.git

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

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

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

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

Reference:

 

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

发表评论