Creating and Sharing a Git Repository Over HTTP

Version Control System is a software that helps software developers to work together and maintain a complete history of their work.Git and SVN are popular version control systems.Among them Git is the most used and actively developed open source version control system.In this tutorial, I will cover setting up a git repository and sharing it via HTTP.

1. INSTALLING GIT ON UBUNTU

Git is cross platform and can be installed easily.On Ubuntu, just open terminal and type

sudo apt-get update

sudo apt-get install git

NOTE:There is ​package called git-core in the repository.The git-core package is a “dummy” package, which has the git package as dependency. This is because the git-core package has been renamed to git.

2. CREATING A BARE REPOSITORY

A bare repository is used for sharing. If you are collaborating with a team of developers, and need a place to share changes to a repo, then you will want to create a bare repository in centralized place where all users can push their changes.Developers will clone the shared bare repo, make changes locally in their working copies of the repo, then push back to the shared bare repo to make their changes available to other users.To create a bare repository named ‘myrepo’ use following commands.Bare repo contains .git extension in repository name.The option –shared make the repository able to be accessed by anyone.

mkdir git

cd git

git init --bare --shared myrepo.git

NOTE:We cant add files to a bare repository directly.Files can be pushed to bare repository after cloning a working repository.

3. INSTALLING APACHE WEB SERVER

A web server is the software that receives your request to access a web page and serves the web page.Apache HTTP Server is a free and open-source cross-platform web server software. Apache is developed and maintained by an open community of developers under the Apache Software Foundation.Here we are using Apache to share the git repo over http.Apache server can be installed by following command.

sudo apt install apache2

4. Installing required modules for Apache

Now we have to install some Apache modules to extend functionality.Enable required modules by

a2enmod env alias cgi auth_digest

  • env: This module allows for control of internal environment variables that are used by various Apache HTTP Server modules.
  • alias: Provides for mapping different parts of the host file system in the document tree and for URL redirection
  • cgi: Execution of CGI scripts
  • auth_digest:User authentication using MD5 Digest Authentication

Restart apache to apply changes.

sudo service apache2 restart

5. Change directory permissions

Now change the permissions of the git repository so that apache can access the repository.Use the following command for that.-R option will recursively change the ownership of all repository contents to apache.

chown -R www-data.www-data /path/to/gitrepo

6. Creating a site for sharing repository

To access git repository over http,we have to define a ‘site’ for the repository.For that add a new git.conf file to /etc/apache2/site-available

cd /etc/apache2/sites-available

sudo vi git.conf

Now add following content to the file.Don’t forget change the file according to your system details.

https://github.com/basilky/git-over-http/blob/master/git.conf

7. Enable site and clone the repository

Now enable the website as

sudo a2ensite git

Now,our git repository can be cloned as

git clone http://git.example.com/myrepo.git

But, to redirect the request to the host computer and not the internet,add the url into /etc/hosts,so that the first line will look like

127.0.0.1     localhost       git.example.com

Now we can clone our repository.Output will look like

Cloning into ‘myrepo’…

Username for ‘http://git.example.com’: basil

Password for ‘http://[email protected]’:

warning: You appear to have cloned an empty repository.

Checking connectivity… done.

Now, if needed, you can set authentication for the repository.I was using Ubuntu 16.04 for creating this tutorial.Procedures will be pretty much similar for any Linux distro.Use the comment box below if you find any problems.I will be happy to help.

Leave a Reply

Your email address will not be published. Required fields are marked *