Welcome to Part 2 of “Learn GIT series”.
Purpose: So in our last part we saw how to install GIT on Debian and how to create a new repository and make commits on it. In this part we will see how you can make your repositories public (read-only) so that people can see what you have been working and what things have changed. Basically our goal is to create a publish our repositories on a web server like Apache just like GIT projects on kernel.org and debian.org.
So let’s get started…
Step 1: Install and configure Apache server
Before we make our repositories public we need a web-server installed on our system.
# apt-get install apache2
For more details refer to the mediawiki post.
Step 2: Install gitweb package
Now we need to install some basic files which will enable us to publish our repositories on Apache server:
# apt-get install gitweb
This will create a directory called “git” and will also create some HTML-related files:
debian-tablet:~# ls /var/www/git/
git-favicon.png git-logo.png gitweb.cgi gitweb.css indextext.html
Step 3: Modify gitweb.conf file
Now we will make some simple modifications to the gitweb’s configuration file:
debian-tablet:~# nano /etc/gitweb.conf
And make sure your gitweb file looks like as follow:
# path to git projects (<project>.git)
$projectroot = "/var/cache/git";
# directory to use for temp files
$git_temp = "/tmp";
# target of the home link on top of all pages
$home_link = "/git/";
# 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
$stylesheet = "gitweb.css";
# logo to use
$logo = "git-logo.png";
# the 'favicon'
$favicon = "git-favicon.png";
I suggest you simply copy paste the above file. Basically all our GIT repositories that we will publish will be copies/stored at /var/cache/git which is the default location in Debian. You can change it to whatever you want, however I would suggest that you keep it just like that. Notice the removal of “/” from variables $stylesheet, $logo, $favicon.
Step 4: Initialize a bare copy of your working repository
From our last part, we saw how we created a fresh repository called “hello”. We will make this same repository as publishable so that people can browse them.
First go to the parent directory where “hello” repository is stored.
kushalk@debian-tablet:~$ cd projects
You should be able to see the “hello” project repository if you followed the steps in Part 1 of this series:
Now we will first clone/initialize a bare “hello” repository
# git clone --bare hello hello.git
If you want to save yourself from lot of trouble in future, please do the above step exactly as mentioned.
Step 5: Make your GIT repository exportable
Finally we need to tell git-daemon to make this repository exportable so that people can see it. First make sure that the git-daemon is running by giving following command:
kushalk@debian-tablet:~/projects$ cat /etc/services | grep ^git
git 9418/tcp # Git Version Control System
And then make the repository “hello.git” exportable.
kushalk@debian-tablet:~/projects$ touch hello.git/git-daemon-export-ok
Basically we need to create a file called “git-daemon-export-ok” to tell git-daemon that we want this repository to be exportable.
Step 6: Copy the bare repository to make it publishable
Now remember the variable $projectroot from /etc/gitweb.conf file from Step 3? We will copy the bare repository in that location to make it publishable:
debian-tablet:/home/kushalk/projects# mv hello.git/ /var/cache/git/
You will require “root” access to do the above step.
Step 7: Finally browse your directory in apache web-server
Finally the time has come to see the results of your hard work that you have been doing. Fire up a web-browser and type the following in the address bar:
Violla!!!! You see your GIT repository listed in the web browser like this:
Step 8: Delete original repository and clone a new one
Now you can safely remove your original repository “hello” that we created in Part 1 – Why? Because now we will clone the web repository that we just created and will continue our work from there.
kushalk@debian-tablet:~/projects$ rm -rf hello
And now finally we will clone a repository from a web-server and start our work from there just like the Pros.
kushalk@debian-tablet:~/projects$ git clone /var/cache/git/hello.git/ hello
kushalk@debian-tablet:~/projects$ ls hello/
As you can see the files that we created in Part 1 are there with all the modifications!
Please note that there might be other ways to achieve the above process but I found this one works the best for me on Debian after 3-4 days of research.
In our next part, we will learn how to clone and push changes from another machine – the real world scenario!