You might want to protect a gitweb instance with authentication like i did. Here is how. This was done on Debian. Most distributions should have the file in the same locations.

Configuring apache

/etc/apache/conf.d/gitweb

Alias /gitweb /usr/share/gitweb

<Directory /usr/share/gitweb>
  AuthType Basic
  AuthName "Restricted Area 51"
  AuthBasicProvider file
  AuthUserFile /usr/share/gitweb/.htpasswd
  Require valid-user
  Options FollowSymLinks +ExecCGI
  AddHandler cgi-script .cgi
</Directory>

The htpasswd file

Note that you will have to replace $USER with your desired user name:

#Create it

htpasswd -c /usr/share/gitweb/.htpasswd $USER

#Add another user(optional)

htpasswd /usr/share/gitweb/.htpasswd $USER

#Delete a user(notice)

htpasswd -D /usr/share/gitweb/.htpasswd $USER

That’s it

restart apache: service apache2 restart