What do you need.
- linux server (in my case ubuntu 12.04.4)
- git-core (available via apt-get)
- gitweb (also available via apt-get)
Installing the packages
This tutorial will install Git on apache 2.2 with gitweb
I’m going to assume that you know the basics of linux and that you should have no problem with installing packages through apt-get install and know how to configure them.
First we start off with the installation of git-core. Most of the time it is already installed on Ubuntu. But if not here is the command.
1 |
sudo apt-get install git-core |
Creating you git repository
I have created a Git repository under /var/lib/git, this can be any location on your machine. For the sake of the tutorial i’m going to stick with /var/lib. This was done because of a side installation of Trac.First, prepare a folder for your repository.
1 2 3 |
sudo mkdir /var/lib/git sudo mkdir /var/lib/git/YourProject |
Change the YourProject to an useful name for your repository, like website or development.
Next, initialize your git repository
1 2 3 |
sudo git init /var/lib/git/YourProject sudo chown -R www-data:www-data /var/lib/git/YourProject |
In the command line you can see that we chown the repository, this is for gitweb that you install later on.
Next head in to your repository and open the .git folder. Now prepare the hooks folder
1 2 3 4 5 6 7 8 9 |
cd hooks sudo mv post-update.sample post-update sudo chmod a+x post-update cd .. sudo git update-server-info |
Git is now ready to accept HTTP requests, but at the moment there is no way to authenticate with git. Make a file in your conf.d folder of apache2 and name it git.conf. Add the following lines in the file.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
SetEnv GIT_PROJECT_ROOT /var/lib/git SetEnv GIT_HTTP_EXPORT_ALL ScriptAlias /git /usr/lib/git-core/git-http-backend/ <Location /git> AuthType Basic AuthName "Git" AuthUserFile /etc/git/passwd.git Require valid-user </Location> CustomLog /var/log/apache2/git-access.log combined ErrorLog /var/log/apache2/git-error.log |
And restart apache2
1 |
sudo service apache2 restart |
Now to make the password file for git. I have placed the password file in a seperate folder in the /etc/ folder.
1 |
sudo htpasswd -c passwd.git <user> |
after this you can just user htpasswd passwd.git <user> to add other users. For this to work you have be inside the directory.
Installing gitweb
This couldn’t be more simple under Ubuntu.
1 |
sudo apt-get install gitweb |
And you’re done. If you now open http://<ip/domain>/gitweb you will see gitweb. But there is an error that there is no projects. Let’s start configuring gitweb.
1 2 3 |
cd /etc sudo nano gitweb.conf |
You will get the following
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# path to git projects (<project>.git) #$projectroot = "/var/cache/git"; $projectroot = "/var/lib/git"; # directory to use for temp files $git_temp = "/tmp"; # target of the home link on top of all pages #$home_link = $my_uri || "/"; # html text to include at home page #$home_text = "indextext.html"; # file with project list; by default, simply scan the projectroot dir. #$projects_list = $projectroot; # stylesheet to use #@stylesheets = ("static/gitweb.css"); # javascript code for gitweb #$javascript = "static/gitweb.js"; # logo to use #$logo = "static/git-logo.png"; # the 'favicon' #$favicon = "static/git-favicon.png"; # git-diff-tree(1) options to use for generated patches #@diff_opts = ("-M"); @diff_opts = (); |
Now change the $projectroot to the root of your git repositories. In my case that is /var/lib/git. Now save and exit.
Last, do for every repository the following command
1 |
sudo git config --bool core.bare true |
You should now be able to login with HTTP over git and use your repository.
For more info about Git and Ubuntu
All web pages open in a new tab or window.