📜 ⬆️ ⬇️

Install and configure cGit on Ubuntu

With the help of this article (step-by-step instructions) you can create your own Git repository, with a cGit -based web interface.

So, simply and concisely, the standard cGit (clickable) looks like:


Now virtual dedicated servers (VPS, VDS) have become very popular. For 5-15 dollars a month, you can afford to use almost full-fledged hosting, with individual settings, good resources and almost everything your heart desires. My soul wants to use the Git version control system. She has a lot of advantages, among which the main ones are speed and convenience. I used SVN for quite a long time (not on my own) and I was very surprised when I tried Git. The development process, merging branches, switching from branch to branch and updating is extremely convenient, fast and smooth! As a web muzzle, I chose cGit, because I met quite a few places where it is used, it is small and fast. And also because I really didn't like gitweb, which for some reason is more popular. Ubuntu OS 9.04 and 9.10 are installed on my server and client, respectively. All actions will be performed in the console. The instruction is designed for a novice user.

First of all (if you have not done it yet) we will need to install LAMP on a remote computer (it is the server, it is also the future storage). To do this, just execute in ubunt:
sudo tasksel install lamp-server 

Next we download the latest version of cGit and compile it. For this we need some libraries and programs. To install them - run:
 sudo apt-get install libcurl4-openssl-dev git-core build-essential mc 

We installed the packages for compilation, the file manager mc (with its very convenient editor mcedit) and the Git toolkit itself. Let's start compiling and installing:
 git clone git://hjemli.net/pub/git/cgit cd cgit/ git submodule init git submodule update make 

Download about 20 MB. Wait for a successful compilation and linking (usually not longer than a few minutes). As a result, we have a cgi-script, logo and css file for the future repository. cGit we will install and configure manually.
')
Several options are possible further, depending on how you want to access cGit. It was convenient for me to contact the subdomain. For example: git.example.ru . To do this, create a new virtual host (the name of the remote user is projects ):
 sudo touch /etc/apache2/sites-available/cgit sudo mcedit /etc/apache2/sites-available/cgit 

And insert into the file a piece of code (do not forget to change the domain to your own):

 <VirtualHost *:80> ServerName git.example.ru DocumentRoot /home/projects/www/cgit DirectoryIndex cgit.cgi SetEnv CGIT_CONFIG /etc/cgitrc <Directory "/home/projects/www/cgit"> Options FollowSymlinks ExecCGI Allow from all AllowOverride all Order allow,deny <Files cgit.cgi> SetHandler cgi-script </Files> </Directory> <Directory "/home/projects"> Allow from all </Directory> </VirtualHost> 


Create a directory for cGit and copy the compiled files there:
 mkdir ~/www/cgit -p cd ~/cgit cp cgit ~/www/cgit/cgit.cgi cp cgit.png ~/www/cgit/ cp cgit.css ~/www/cgit/ 

Create a configuration file for cGit and write the settings in it:
 sudo touch /etc/cgitrc sudo mcedit /etc/cgitrc 

The editor opens. Here are my contents of the config, with comments:
 #     virtual-root=/ #     . css=/cgit.css logo=/cgit.png #    Git . scan-path=/home/projects #   ... enable-index-links=1 enable-log-filecount=1 enable-log-linecount=1 #  root-title=  # root-desc=    ,     ? #  ,     (  ) snapshots=tar.gz tar.bz2 zip #  ( ,   )  repo.url=temp repo.path=/home/sartor/www/temp/.git repo.desc=    repo.owner=Sartor repo.url=exp repo.path=/home/sartor/www/exp/.git repo.desc=Experimentum repo.owner=Sartor 

Now everything is ready for launch. Add a virtual host to the list of allowed ones and restart Apache:
 sudo a2ensite cgit sudo /etc/init.d/apache2 restart 

Go to git.example.ru and make sure that everything works.
If there is a 50x error, you need to do the following:
 sudo touch ~/www/cgit/.htaccess sudo mcedit ~/www/cgit/.htaccess 

And insert the following contents (don't forget to change the paths to your own):
 RewriteEngine on RewriteCond %{HTTP_HOST} ^git\. RewriteCond %{REQUEST_FILENAME} -f RewriteRule .* - [L] RewriteCond %{HTTP_HOST} ^git\. RewriteRule ^git/$ /home/projects/www/cgit/cgit.cgi [L] RewriteCond %{HTTP_HOST} ^git\. RewriteRule ^(.*)$ /home/projects/www/cgit/cgit.cgi?url=$1 [L,QSA] 

Now it will definitely work :)
To check whether everything works correctly, create a repository with a single file:
 mkdir ~/test cd ~/test touch habr.txt echo " , " > habr.txt git init git add . git commit -m " " 

We update starnichka in the browser and see our first commit.

Summarize what we have done and how to use it:
On the remote server, we created a web interface for the popular Git version control system. It is accessed through the git subdomain.

I will describe the approximate developer script:
  1. I create a new folder on the server (for example, www / test ) at home.
  2. I do git init in it.
  3. On the local machine I do git clone projects@example.ru: www / test / .git . This will create a local copy of the remote repository (as long as it is empty).
  4. I throw a bunch of files into the local folder that we created in the previous step. I do, so to speak, the framework of the project. If necessary, add exceptions (.gitignore).
  5. I execute git add. && git commit && git push , commenting on my changes.
  6. Everything. Local and remote repositories updated and synchronized.
  7. I work on the project. After any meaningful changes, I’ll do step 5 again. Do not forget to go to the folder with which you worked. Especially lazy cunning can do alias for bash.

If you are a web developer and you need to quite often show the current result of work, it will be very useful to put the post-receive file in the .git / hooks folder of a project with the following contents:
 #!/bin/sh cd .. env -i git checkout -f echo "   !" 

And give him the right to perform. Now, after each update (step 5), the project's working tree will also be updated and real files will always be the latest, up-to-date version (and almost everyone expects it when they update the remote repository, but this does not happen by default).

Learning how to work with git is quick and intuitive. For this hard currency there is a lot of information in different languages, and with the web interface it will be even easier to use.

I do not pretend to the purity of configs, the admin from me is not very. But they are guaranteed to work.

Source: https://habr.com/ru/post/86753/


All Articles