Run Git Server on Top of Apache with SSL

This article covers the steps to setup a git server on top of apache http server with ssl authentication.

Server side

Make sure you have git and open ssl installed.

Create git dir:

mkdir -p /var/www/html/git

Create git repository:

cd /var/www/html/git
git --bare init [reponame].git
git update-server-info
chown -R apache:apache .

Config apache:

vim /etc/apache2/conf.d/git.conf

Add following:

<Location /git/[reponame].git>
    DAV on
    AuthType Basic
    AuthName "Git"
    AuthUserFile /etc/auth-file
    Require valid-user

Create auth file:

htpasswd -c /etc/auth-file [myusername]

Restart apache:

sudo service httpd restart

Client side

Clone the repository:

git clone https://[hostname]/git/[reponame].git

For self-signed certificate:
Add “GIT_SSL_NO_VERIFY=true” to your environment variables

Create sample file and push it into empty repository:

cd [reponame]
echo test file > readme.txt
git add readme.txt
git commit
git push origin master

For the following pushes you can simply use:

git push

If you don’t want to be prompted for the password each time and you don’t mind storing it in plain text, edit following file:

vim ~/.netrc

and add following:

machine [hostname]
login [myusername]
password [mypassword]


  1. Git tutorial:

  2. Use apache auth:

  3. SSL issue:

  4. Git web:

  5. Git cheat sheet: