Cgit is a simple and light-weight web interface for Git Repositories. It uses cgi script, implemented in C, to generate web-interface. Cgit is very commonly used by a lot of open source projects which hosts there Git Repositories, like Linux Kernel, GNOME, KDE. Most of the popular Linux distributions have Cgit in there official repository.


Cgit also supports syntax highlighting for a lot of languages using a package called highlight. But it is not critical for Cgit to run. Therefore, highlight is an optional package and can be skipped.


$ apt-get install cgit highlight git


$ apk --update add cgit highlight git


$ pacman -S cgit highlight git

Note: Requires admin privilege.


For setup, it is recommended to use a separate user to handle Git Repositories. It is also recommended to change the default shell, (Bash generally) of that user to git-shell so that users with pull and push access cannot directly run shell on the system.


$ adduser git
sudo adduser git
Adding user `git' ...
Adding new group `git' (1002) ...
Adding new user `git' (1002) with group `git' ...
Creating home directory `/home/git' ...
Copying files from `/etc/skel' ...
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
Changing the user information for git
Enter the new value, or press ENTER for the default
	Full Name []: git
	Room Number []:
	Work Phone []:
	Home Phone []:
	Other []:
Is the information correct? [Y/n] y

$ sudo chsh -s /usr/bin/git-shell git


$ adduser -S git -s git-shell


$ useradd -m -g git -s /usr/bin/git-shell git

git user is now going to use git-shell, which by default do not allow interactive use. However, the administrator might need to use Bash for various reasons. For that an alias can be added to the administrator’s .bashrc file so that git-user can be used to run Bash.

$ echo "alias git-user='sudo -u git -s'" >> ~/.bashrc

Note: Requires sudo package.

As no one is directly going to do anything with the repositories, its better to use bare Git repositories. Use the following command to setup a bare Git repository.

$ git-user
$ git init --bare repo.git

Cgit uses a runtime configuration file to set various options. The file is located under /etc/cgitrc. cgitrc.5.txt gives detailed information about all the options which can be used inside the runtime configuration file.

A web-server which supports cgi needs to be setup in order to serve Cgit. Common choices are Apache and Nginx.

Check this gist for configuration files for both servers as well as a sample runtime configuration file.

Particularly in Debian, Cgit package also installs an Apache Mod which can be used directly.

See Also