MCPSERV.CLUB
Cgit

Cgit

Self-Hosted

Fast, lightweight Git web interface in C

Stale(40)
0stars
0views

Overview

Discover what makes Cgit powerful

Cgit is a **hyper‑fast, CGI‑based web front‑end for Git repositories** written in C. It exposes a lightweight HTTP interface that renders repository data on demand, caching the resulting HTML to keep response times low. The core idea is to provide a minimal yet feature‑rich browsing experience without the overhead of a full web application stack. Cgit is distributed under GPLv2, making it free to use and modify for internal or public deployments.

Repository browsing

Dumb HTTP transport

Atom feeds

On‑the‑fly archives

Overview

Cgit is a hyper‑fast, CGI‑based web front‑end for Git repositories written in C. It exposes a lightweight HTTP interface that renders repository data on demand, caching the resulting HTML to keep response times low. The core idea is to provide a minimal yet feature‑rich browsing experience without the overhead of a full web application stack. Cgit is distributed under GPLv2, making it free to use and modify for internal or public deployments.

Key Features

  • Repository browsing: logs, diffs (inline and side‑by‑side), tree views, commit statistics, author/committer filters.
  • Dumb HTTP transport: cloneable URLs that implement the Git HTTP protocol, allowing git clone over plain HTTP.
  • Atom feeds: per‑repository commit streams in Atom format for integration with RSS readers or CI pipelines.
  • On‑the‑fly archives: tar/zip generation for tags and commits without pre‑creating archive files.
  • Plugin architecture: dynamic loading of shared libraries for syntax highlighting, custom filters, or other extensions.
  • Lua scripting: an embedded interpreter that powers a flexible filtering framework (e.g., grep, pretty-blob-view).
  • Virtual hosting: macro expansion to serve multiple repositories from a single CGI instance.

Technical Stack

LayerTechnology
LanguageC (ANSI‑C, portable across Unix‑like systems)
RuntimeCGI via mod_cgi or standalone FastCGI; no database required
HTTPStandard CGI interface, optionally behind Nginx/Apache for load balancing
TemplatesBuilt‑in HTML templates with placeholder macros; can be overridden by custom CSS/JS
Data storageGit objects on disk; no external DB (caching uses file‑based ETag/mtime checks)
ExtensionsShared objects (.so / .dll) loaded at runtime; Lua scripts stored in a filter/ directory

The absence of a heavyweight framework makes Cgit extremely small (≈ 200 KB binary) and fast to compile, while still being highly configurable through a plain text config file (cgitrc).

Core Capabilities & APIs

  • HTTP API: GET /repo/commit/<hash> returns HTML; GET /repo/archive/<ref>.tar.gz streams an archive. The server also supports the Git smart HTTP protocol for git clone, but primarily implements the dumb protocol.
  • Atom API: /repo/atom delivers a feed of recent commits, consumable by any Atom‑compatible client.
  • Plugin API: Functions exported from plugins can be invoked during rendering (e.g., syntax highlighters). The API is documented in the source under plugins/.
  • Lua API: Filters expose Git data via Lua tables; developers can write custom filtering logic without recompiling Cgit.

Deployment & Infrastructure

  • Self‑hosting: Runs on any POSIX system with a C compiler and standard libraries. No external services needed beyond the web server.
  • Scalability: Because each request is stateless, horizontal scaling is achieved by running multiple CGI instances behind a load balancer (Nginx fastcgi_pass or Apache ProxyPass). Cgit’s caching layer reduces disk I/O, making it suitable for repositories with high read traffic.
  • Containerization: Official packages exist for Arch, Gentoo, Fedora/RHEL/CentOS, OS X, OpenSUSE, NetBSD, and FreeBSD. Docker images are available on GitHub Container Registry (ghcr.io/zx2c4/cgit), allowing quick spin‑up in CI/CD pipelines.
  • Resource footprint: Minimal RAM usage (< 10 MB per instance) and negligible CPU overhead, making it ideal for edge or embedded deployments.

Integration & Extensibility

  • Plugins: Add syntax highlighters (e.g., highlight.js wrapper), custom diff formats, or external search backends. Plugins are loaded via the plugin_dir directive in cgitrc.
  • Webhooks: While Cgit itself does not provide outbound webhooks, its integration with Gitolite or pre‑push hooks can trigger external services (e.g., CI jobs) when new commits are pushed.
  • Custom templates: Override HTML fragments to match corporate branding or integrate with single‑sign‑on systems.
  • Virtual hosting: Use repo_path and url_prefix macros to expose multiple repositories under a single domain, simplifying DNS management.

Developer Experience

  • Configuration: cgitrc is a simple key/value file; most settings are self‑explanatory. The --help flag prints available options, and the source contains extensive comments.
  • Documentation: The README covers build steps, packaging, and advanced configuration. The FAQ addresses common pitfalls (e.g., CGI timeouts, cache invalidation).
  • Community: Mailing list (cgit@zx2c4.com) and IRC channel (#cgit on Libera.Chat) provide active support. The project is actively maintained with frequent releases, and contributors are encouraged to submit patches via the Git repo.

Use Cases

  1. Enterprise Code Browsing: Deploy a single Cgit instance to host internal Git repositories, providing developers with fast read access without exposing the raw Git server.
  2. Open‑Source Project Portals: Host public repos with minimal overhead; the lightweight binary fits well on inexpensive VPS or even Raspberry Pi.
  3. **

Open SourceReady to get started?

Join the community and start self-hosting Cgit today