GitWeb: Visualize your local repositories

Photo by Yancy Min on Unsplash

GitWeb: Visualize your local repositories

GitWeb is a web-based interface for browsing Git repositories. It comes bundled with Git itself, so if you've installed Git on a server, you likely already have GitWeb. It provides a visual representation of repositories, allowing you to explore commits, branches, tags, and other Git objects directly from a web browser.

Some features of GitWeb:

  1. Repository Browser: View the content of directories, the content of files, and the history of files.

  2. Commit Viewer: Examine details of specific commits, including diffs, stats, and the commit message.

  3. Branch and Tag Lists: See lists of branches and tags, and navigate through their corresponding commits.

  4. Search: Search for commits by author, comitter, and revision hash.

  5. Blame: Look at the 'blame' of a file, showing which line was edited by which commit.

  6. RSS Feeds: Get RSS feeds for the project's history.

  7. Highlighting: Syntax highlighting for code files to make them more readable.

  8. Configurable Look and Feel: Although GitWeb's appearance is quite basic, you can customize it to some extent using stylesheets.

Setting Up GitWeb

  1. GitWeb is a Perl script, so you'll need to have Perl installed on your server.

  2. For syntax highlighting, GitWeb requires the highlight package.

  3. Depending on how you installed Git, GitWeb might be present in a directory like /usr/share/gitweb/ or somewhere similar.

  4. You will often see GitWeb integrated with web servers like Apache or nginx. The web server will need to be set up to execute the GitWeb script for incoming requests and serve the appropriate pages.

It's worth noting that while GitWeb is a straightforward way to get web-based access to Git repositories, many organizations opt for more feature-rich platforms like GitHub, GitLab, or Bitbucket for hosting and viewing repositories. These platforms offer a broader set of features like pull request management, issue tracking, CI/CD integration, and more. However, for simpler use cases or internal server setups, GitWeb might be a good fit.

Installation and start

To run GitWeb on an Ubuntu machine first, you have to install lighttpd package:

sudo apt install lighttpd

To run GitWeb use the following command:

git instaweb

This command will locally open a web page hosted on port 1234:

To stop the running instance of the GitWeb use the command:

git instaweb --stop

Instaweb command

git instaweb is a Git command used to start a web server with an interface into your repository. When you run it, it automatically fires up your preferred web browser and serves an interactive web-based tool to browse your repository, view commit history, diff between commits, and so on.

Under the hood, git instaweb uses a Git web interface such as gitweb, cgit, or others to provide this functionality. Which interface is used depends on your Git configuration and what's installed on your system.

Here's a quick overview of how to use it:

  1. Starting git instaweb:

     git instaweb [--local] [--httpd=<webserver>] [--port=<port>] [--browser=<browser>]
    
    • --local: Binds the web server to the local network interface (127.0.0.1).

    • --httpd=<webserver>: You can specify the web server to use, e.g., lighttpd, apache, etc.

    • --port=<port>: You can specify the port number on which the web server should listen.

    • --browser=<browser>: Specify the web browser to use.

  2. Stopping git instaweb:

     git instaweb --stop
    
  3. Configuration: git instaweb uses various configuration options to determine how it behaves. You can set these options using the git config command. Some of the configurations include:

    • instaweb.browser: The web browser to use.

    • instaweb.httpd: The web server to use.

    • instaweb.port: The port for the web server.

    • ... and many others related to the web server and the interface.

Remember, to use git instaweb, you'd need to have the necessary dependencies installed. For example, if you're using gitweb as the interface and lighttpd as the web server, both of these need to be installed and properly configured on your machine.

git instaweb is especially useful when you want a visual representation of your repository's history, but don't want to push the repository to a platform like GitHub or GitLab or set up a dedicated Git server. It's a quick way to get a web-based view of your local repository.

References

  1. Git on the Server - GitWeb

  2. lighttpd

  3. highlight package

  4. https://github.com/git/git/tree/master/gitweb