GIT – In software development, Git (/ɡɪt/) is a distributed revision control and source code management (SCM) system with an emphasis on speed.[3] Git was initially designed and developed by Linus Torvalds for Linux kernel development; it has since been adopted by many other projects

Table of Contents

  • Installing and configuring Git
  • Configuring Apache and Gitweb
  • Using Git and Gitweb

General Information

In this article we will see how you can create Git repositories under .

This article will not teach you on how to use Git, it will only cover the installation and configuration of Git and Gitweb on FreeBSD, plus showing you how to use Apache with Gitweb.

In the following documentation we will also see how you can create public and private protected Git repositories.


  • root access or sudo rights
  • You have installed and configured Apache already. If you don’t have Apache installed on your FreeBSD box, please refer to the following document, which explains how to install Apache under FreeBSD.


The first thing you need to have installed is to get Apache running on your FreeBSD box.

Please, refer to the following documentation on how to install and configure Apache. While following that documentation, please keep in mind to skip all those steps, where you need to support for Apache.

Now, let’s go ahead and install Git:

# cd /usr/ports/devel/git && make install clean

After you execute the above , you should see the following screen below:

Git Config

NOTE: Please, note that SVNP4, CVS and CURL are optional. Select them, only if you intend on using them. Also, please make sure that you selectGITWEB.

Once the installation is over you should see something similar:

In the directory /usr/local/share/examples/git/gitweb you can find all files to
make gitweb work as a public repository on the web.
All you have to do to make gitweb work is:
1) Copy the files /usr/local/share/examples/git/gitweb/git* to a directory on
   your web server (e.g. Apache2) in which you are able to execute
2) In gitweb.cgi, adjust the variable $projectroot to point to
   your git repository (that is where you have your *.git project
===> Installing rc.d startup script(s)
===>   Compressing manual pages for git-
===>   Registering installation for git-
===> REPORT:
      This port has installed the following files which may act as network
      servers and may therefore pose a remote security risk to the system.
      This port has installed the following startup scripts which may cause
      these network services to be started at boot time.
      If there are vulnerabilities in these programs there may be a security
      risk to the system. FreeBSD makes no guarantee about the security of
      ports included in the Ports Collection. Please type 'make deinstall'
      to deinstall the port if this is a concern.
      For more information, and contact details about the security
      status of this software, see the following webpage:
===>  Cleaning for git-

Now that we have Git installed, let’s configure it.

Configuring Git

We are going to do a very basic configuration of Git. For more information and all configuration options of Git, please refer to the git-config(1) manual page.

# git config --global "<your-name>"
# git config --global "<your-email>"
# git-config --global core.editor vim
# git-config --global core.pager less

We will use a dedicated user for the Git repositories, which will be able to push to the remote repos. The user will be named git, and the Git repositories will be located in the /home/git directory. We will also create two kinds of repositories – a public one, and a private protected one. Those will be respectively under /home/git/private and /home/git/public.

The public Git repository will be publically accessible, while the private Git repository will require user authentication when browsing it’s content from a browser.

Now, let’s create the git user and group:

# pw groupadd -n git -g 9418
# pw useradd -n git -u 9418 -g git -c "Git User Account" -d /home/git \
    -s /usr/local/libexec/git-core/git-shell -h -

Creat the directories that will be keeping the private and public repositories and set proper permissions:

# mkdir -p /home/git/private
# mkdir -p /home/git/public
# chown -R git:git /home/git
# chmod -R 0755 /home/git

For every user that needs commit access to the remote repositories, collect their public SSH keys and put them to the authorized_keys file:

# mkdir -p /home/git/.ssh
# touch /home/git/.ssh/authorized_keys
# chown -R git:git /home/git/.ssh
# chmod 0700 /home/git/.ssh
# chmod 0600 /home/git/.ssh/authorized_keys

Every new user that needs commit access you will need to get his/hers public key and then put it to /home/git/.ssh/authorized_keys file.

On the next step we will configure Apache and Gitweb, so we can browse our repositories from the browser.

Configuring Gitweb

Assuming you have followed the documentation for installing and configuring Apache, we will now configure the Web interface to Git repositories – Gitweb.

We will also make some changes to our Apache configuration, so it is able to run Gitweb.

Please also, note that in this documentation we will be creating two kinds of repositories – a private and a public one. Both of these repositories will be running on the same Git server, which is called, but we will use Apache vhosts in order to separate the public and private repos when browsing the repos with Gitweb.

So, let’s go ahead and configure Gitweb now. The Gitweb files will be under /usr/local/www/gitweb. Now let’s create that directory and copy the needed files:

# mkdir -p /usr/local/www/gitweb
# cp /usr/local/share/examples/git/gitweb/git* /usr/local/www/gitweb

Now open /usr/local/www/gitweb/gitweb.cgi for editing and make the needed changes:

<< SNIP >>
# absolute fs-path which will be prepended to the project path
our $projectroot = $ENV{'GITWEB_PROJECTROOT'};
<< SNIP >>
# name of your site or organization to appear in page titles
# replace this with something more descriptive for clearer bookmarks
our $site_name = ""
                 || ($ENV{'SERVER_NAME'} || "Untitled") . " Git";
<< SNIP >>
# the width (in characters) of the projects list "Description" column
our $projects_list_description_width = 40;

Configuring Apache

Now we are going to configure Apache for Gitweb. Please keep in mind that we are going to have a publically accessible repositories, and private ones.

The reason to have a private repository is perhaps you might want to keep configuration files of a number of systems that contain a lot of information that should not be revealed to anyone. This is where having a private repo comes in hand.

The public repositories will be accessible via and the private via Please note that you are going to use HTTPS only when accessing the private repositories. Also in order to access the private repositories you will need to authorize yourself.

Now, let’s define the public and private repositories in Apache. Please note that the default Apache vhost is the public repository. This is mine httpd-vhosts.conf file. Feel free to suit it for your needs:

# Use name-based virtual hosting.
NameVirtualHost *:80
NameVirtualHost *:443
# Default vhost is
<VirtualHost *:80>
    ServerAdmin [email protected]
    RedirectMatch ^/$ /gitweb.cgi
    SetEnv GITWEB_PROJECTROOT /home/git/public
    Alias /gitweb.js                /usr/local/www/gitweb/gitweb.js
    Alias /gitweb.css               /usr/local/www/gitweb/gitweb.css
    Alias /git-logo.png             /usr/local/www/gitweb/git-logo.png
    Alias /git-favicon.png  /usr/local/www/gitweb/git-favicon.png
    ScriptAlias / "/usr/local/www/gitweb/"
    <Directory "/usr/local/www/gitweb/">
        AllowOverride None
        Options Indexes FollowSymLinks ExecCGI
        Order allow,deny
        Allow from all
    ErrorLog "/var/log/apache/"
    CustomLog "/var/log/apache/" common
# vhost
# Requires authorization and uses SSL only
<VirtualHost *:80>
  Redirect permanent /
<VirtualHost *:443>
    ServerAdmin [email protected]
    SSLEngine On
    SSLCertificateFile "/etc/ssl/apache/server.crt"
    SSLCertificateKeyFile "/etc/ssl/apache/server.key"
    RedirectMatch ^/$ /gitweb.cgi
    SetEnv GITWEB_PROJECTROOT /usr/home/git/private
    Alias /gitweb.js                /usr/local/www/gitweb/gitweb.js
    Alias /gitweb.css               /usr/local/www/gitweb/gitweb.css
    Alias /git-logo.png             /usr/local/www/gitweb/git-logo.png
    Alias /git-favicon.png          /usr/local/www/gitweb/git-favicon.png
    ScriptAlias / "/usr/local/www/gitweb/"
    <Directory "/usr/local/www/gitweb/">
        AllowOverride None
        Options Indexes FollowSymLinks ExecCGI
        Order allow,deny
        Allow from all
        AuthType Basic
        AuthName "Authorization Required"
        AuthUserFile /usr/local/www/htaccess/git-priv-access
        Require valid-user
    ErrorLog "/var/log/apache/"
    CustomLog "/var/log/apache/" common

And this is mine httpd-ssl.conf file, please make the appropriate changes as needed. Note that this is the default HTTPS vhost for Apache, which is the public repository:

Listen 443
AddType application/x-x509-ca-cert .crt
AddType application/x-pkcs7-crl    .crl
SSLPassPhraseDialog  builtin
SSLSessionCache        "shmcb:/var/run/ssl_scache(512000)"
SSLSessionCacheTimeout  300
SSLMutex  "file:/var/run/ssl_mutex"
## SSL Virtual Host Context
<VirtualHost *:443>
# General setup for the virtual host
ServerAdmin [email protected]
SetEnv GITWEB_PROJECTROOT /home/git/public
RedirectMatch ^/$ /gitweb.cgi
Alias /gitweb.css       /usr/local/www/gitweb/gitweb.css
Alias /git-logo.png     /usr/local/www/gitweb/git-logo.png
Alias /gitweb.js        /usr/local/www/gitweb/gitweb.js
Alias /git-favicon.png  /usr/local/www/gitweb/git-favicon.png
ScriptAlias / "/usr/local/www/gitweb/"
<Directory "/usr/local/www/gitweb">
  AllowOverride None
  Options Indexes FollowSymLinks ExecCGI
  Order allow,deny
  Allow from all
ErrorLog "/var/log/apache/"
TransferLog "/var/log/apache/"
SSLEngine on
#   Server Certificate
SSLCertificateFile "/etc/ssl/apache/server.crt"
#   Server Private Key
SSLCertificateKeyFile "/etc/ssl/apache/server.key"
<FilesMatch "\.(cgi|shtml|phtml|php)$">
    SSLOptions +StdEnvVars
<Directory "/usr/local/www/apache22/cgi-bin">
    SSLOptions +StdEnvVars
BrowserMatch ".*MSIE.*" \
         nokeepalive ssl-unclean-shutdown \
         downgrade-1.0 force-response-1.0
#   Per-Server Logging:
#   The home of a custom SSL log file. Use this when you want a
#   compact non-error SSL logfile on a virtual host basis.
CustomLog "/var/log/httpd-ssl_request.log" \
          "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"

Now, let’s create and secure the file that will be used to authenticate users for the private repositories:

# mkdir -p /usr/local/www/htaccess
# htpasswd -c /usr/local/www/htaccess/git-priv-access <username>
New password:
Re-type new password:
Adding password for user <username>
# chmod 0640 /usr/local/www/htaccess/git-priv-access
# chgrp www /usr/local/www/htaccess/git-priv-access</username></username>

Remember to add all new users that will need access to the private repo, using the the htpasswd utility.

Now we can start up Apache. First check if the Apache configuration is OK and then start Apache.

# apachectl configtest

If the output from the above command says Syntax OK, then we can start up Apache, otherwise you will need to double check your configuration for errors.

# apachectl start

If you haven’t done this already, now is the time to enable Apache during boot-time, so add this line to your /etc/rc.conf file:


In the next we will see how you can create the Git repositories and how to use them.

Creating the Git repositories

Now, let’s create some Git repositories. We will create one public and one private repository, which will be located respectively under the/home/git/public and /home/git/private directories.

# mkdir -p /home/git/private/private-repo.git
# mkdir -p /home/git/public/public-repo.git
# cd /home/git/private/private-repo.git && git init --bare --shared
Initialized empty shared Git repository in /usr/home/git/private/private-repo.git/
# cd /home/git/public/public-repo.git && git init --bare --shared
Initialized empty shared Git repository in /usr/home/git/public/public-repo.git/

Let’s edit the description files from the private-repo.git and public-repo.git directories and set a nice description of the repositories. Now edit the configfiles from the same directories and add these lines at the end of the files. Here’s an example for the public repo, do the same for the private as well.

        owner = <Your Name>
        url = git://

Now, let’s export these repos and set proper permissions, so we can clone and fetch from them:

# touch /home/git/private/private-repo.git/git-daemon-export-ok
# touch /home/git/public/public-repo.git/git-daemon-export-ok
# chown -R git:git /home/git

Starting git-daemon

In order the clients to be able to pull and fetch from the repos we will use the git-daemon(1). Add these lines at the end of your rc.conf file, so that git-daemon is started during boot-time:

# Enable git-daemon
git_daemon_flags="--syslog --base-path=/usr/home/git --detach --reuseaddr"

Now during boot-time the git-daemon will be started as well. To start git-daemon, without rebooting, execute the following command:

# /usr/local/etc/rc.d/git_daemon start

Pushing content to the repositories

Suppose you are a commiter and want to add some files to the already existing and still empty repositories. You will then create a local directory, git-init(1)it, add the files to the index, commit and push them to the remote repo. Note, that this operations requires that your public SSH key is already present in the authorized_keys file on the remote server:

$ mkdir ~/my-git-repo
$ cd ~/my-git-repo && git init
Initialized empty Git repository in /home/user/my-git-repo/
$ git remote add origin [email protected]:/home/git/public/public-repo.git
$ echo foo > bar
$ git add .
$ git commit
$ git push origin master

Cloning the repositories

Now that you want to clone and track the remote repository what you do is this:

$ git clone git://

Using Gitweb

Now that we have some sample content in our repositories, you can navigate through them using your web browser.

Just go to and and you should be able to browse the contents of your private and public repositories.

Print Friendly, PDF & Email



Bài viết liên quan