Difference between revisions of "Git and Gitweb"

From Amahi Wiki
Jump to: navigation, search
Line 26: Line 26:
 
SetEnv GITWEB_CONFIG "/etc/gitweb.conf"
 
SetEnv GITWEB_CONFIG "/etc/gitweb.conf"
 
AddHandler cgi-script .cgi}}</li>
 
AddHandler cgi-script .cgi}}</li>
<li>Restart web server to enable the changes
 
{{Code|/etc/init.d/httpd restart;}}</li>
 
 
<li>Create web page to browse repository</li>
 
<li>Create web page to browse repository</li>
 
{{Code|cd /var/hda/web-apps/gitweb
 
{{Code|cd /var/hda/web-apps/gitweb
Line 47: Line 45:
 
chown -R git:git git
 
chown -R git:git git
 
chmod 755 git}}</li>
 
chmod 755 git}}</li>
<li>Create public SSH key storage
 
{{Code|cd /var/cache/git;
 
mkdir .ssh
 
chmod 700 .ssh
 
touch .ssh/authorized_keys
 
chmod 600 .ssh/authorized_keys
 
chown -R git:git .ssh/}}</li>
 
 
<li>Create '''/etc/init.d/git''' file and add the following
 
<li>Create '''/etc/init.d/git''' file and add the following
 
{{Text|Text=#!/bin/sh
 
{{Text|Text=#!/bin/sh
Line 132: Line 123:
 
<li>Create repository
 
<li>Create repository
 
{{Code|cd /var/cache/git/
 
{{Code|cd /var/cache/git/
mkdir test
+
git init test
cd test
+
cd /var/cache/git/test/</li>
git init
+
<li>Add a short description and test file
chown -R git:git ../test/}}</li>
+
{{Code|echo "test repo" > description}}</li>
<li>Add a short description
+
echo 'test' > README
{{Code|cd /var/cache/git/test/
+
git add README
echo "test repo" > description}}</li>
+
git commit -m "initial README file"}}</li>
 
<li>Edit '''config''' and add the following at the bottom
 
<li>Edit '''config''' and add the following at the bottom
 
{{Text|Text=[gitweb]
 
{{Text|Text=[gitweb]
 
       owner = Your Name}}</li>
 
       owner = Your Name}}</li>
<li>Create local repository and commit
 
{{Code|mkdir ~/test
 
cd ~/test && git init
 
echo 'test' > README
 
git add README
 
git commit -m "initial README file"}}</li>
 
<li>Create SSH rsa public key
 
{{Code|ssh-keygen -t rsa -C "user@yourisp.com"}}</li>
 
<li>Push to the repository
 
{{Code|git remote add origin user@hda.home.com:test
 
git push origin master}}</li>
 
 
<li>Add to bottom of '''/etc/gitweb.conf''' file
 
<li>Add to bottom of '''/etc/gitweb.conf''' file
 
{{Text|Text=$feature{'blame'}{'default'} = [undef];
 
{{Text|Text=$feature{'blame'}{'default'} = [undef];
Line 177: Line 157:
 
{{Code|cp -r /var/www/git/* html
 
{{Code|cp -r /var/www/git/* html
 
chown -R apache:users html}}</li>
 
chown -R apache:users html}}</li>
 +
<li>Restart web server to enable the changes
 +
{{Code|/etc/init.d/httpd restart;}}</li>
 
</ul>
 
</ul>
  

Revision as of 00:15, 15 March 2012

Msgbox-WOPr.png Work In Progress
This article is currently undergoing major expansion or restructuring. You are welcome to assist by editing it as well. If this article has not been edited in several days, please remove this template.


Git is a free & open source, distributed version control system designed to handle everything from small to very large projects with speed and efficiency. Every Git clone is a full-fledged repository with complete history and full revision tracking capabilities, not dependent on network access or a central server. Branching and merging are fast and easy to do. Coupled with Gitweb, provides a web interface for browsing your project.

This tutorial will show you how to install, create a repo, and browse that repo on your HDA.


NOTE: Tested on Fedora 14.

Setup

  • Create web app (Advanced Settings must be enabled on HDA)
    1. From the Dashboard main page, select Apps at the top.
    2. Choose Webapps
    3. Select New Web App button at the bottom
    4. Enter gitweb for the Name (ensure the path reflects the name correctly)
    5. Choose Create
    6. Open a terminal as root user and do the following:
    7. Install dependencies
      bash code
      ​yum -y install git git-daemon gitweb​
    8. Look for the ####-gitweb.conf in /etc/httpd/conf.d (#### is some number, i.e. 1000) file and open it in your favorite editor. Add text after ServerAlias line
      Text
      ​Alias /git /var/hda/web-apps/gitweb/html/ RewriteEngine On RewriteRule ^git$ git/ [R] DirectoryIndex gitweb.cgi SetEnv GITWEB_CONFIG "/etc/gitweb.conf" AddHandler cgi-script .cgi​
    9. Create web page to browse repository
    10. bash code
      ​cd /var/hda/web-apps/gitweb echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <title>Your Page Title</title> <meta http-equiv="REFRESH" content="0;url=http://gitweb/git/"></HEAD> <BODY> Optional page text here. </BODY> </HTML>' > html/index.html chown apache.users html/index.html​
  • Add user
    bash code
    ​useradd -U -d /var/cache/git -s /usr/libexec/git-core/git-shell git​
  • Set directory permissions
    bash code
    ​cd /var/cache chown -R git:git git chmod 755 git​
  • Create /etc/init.d/git file and add the following
    Text
    ​#!/bin/sh # # Startup/shutdown script for Git Daemon # # Linux chkconfig stuff: # # chkconfig: 345 56 10 # description: Startup/shutdown script for Git Daemon # . /etc/init.d/functions DAEMON=/usr/libexec/git-core/git-daemon ARGS='--base-path=/var/cache/git --detach --syslog --export-all --user=git --group=git' prog=git-daemon start () { echo -n $"Starting $prog: " # start daemon daemon $DAEMON $ARGS RETVAL=$? echo [ $RETVAL = 0 ] && touch /var/lock/git-daemon return $RETVAL } stop () { # stop daemon echo -n $"Stopping $prog: " killproc $DAEMON RETVAL=$? echo [ $RETVAL = 0 ] && rm -f /var/lock/git-daemon } restart() { stop start } case $1 in start) start ;; stop) stop ;; restart) restart ;; status) status $DAEMON RETVAL=$? ;; *) echo $"Usage: $prog {start|stop|restart|status}" exit 3 esac exit $RETVAL​
  • Set init script to run
    bash code
    ​chmod 755 /etc/init.d/git; chkconfig git on service git start​
  • Edit /etc/httpd/conf.d/git.conf and replace with this text
    Text
    ​<Directory /var/hda/web-apps/gitweb/html> RewriteEngine On RewriteBase /git/ RewriteRule ^$ gitweb.cgi [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule (.*) gitweb.cgi/$1 [QSA,L] </Directory>​
  • Create repository
    bash code
    ​cd /var/cache/git/ git init test cd /var/cache/git/test/</li> <li>Add a short description and test file {|style="width: 95%; margin-left: 10px; border-collapse: collapse; border-width: 1px; border-style: solid; border-color: #aaa" !style="color:#777; background-color:#dfd;text-align:left"|bash code |- |'"`UNIQ--syntaxhighlight-00000016-QINU`"' |} </li> echo 'test' > README git add README git commit -m "initial README file"
  • Edit config and add the following at the bottom
    Text
    ​[gitweb] owner = Your Name​
  • Add to bottom of /etc/gitweb.conf file
    Text
    ​$feature{'blame'}{'default'} = [undef]; $feature{'pickaxe'}{'default'} = [undef]; $feature{'search'}{'default'} = [undef]; $feature{'grep'}{'default'} = 1; $feature{'snapshot'}{'default'} = ['tgz', 'gzip', 'zip']; $feature{'snapshot'}{'override'} = 1; $site_name = "HDA Git"; $projectroot = '/var/cache/git/'; $projects_list_description_width = 50; $git_temp = "/tmp"; $home_text = "indextext.html"; $site_footer = "indexfooter.html"; $projects_list = $projectroot; $home_link_str = "http://gitweb / git "; $stylesheet = "/git/static/gitweb.css"; $logo = "/git/static/git-logo.png"; $favicon = "/git/static/git-favicon.png"; $feature{'pathinfo'}{'default'} = [1]; $my_uri = "http://gitweb/git/"; $home_link = "http://gitweb/git/;"​
  • Copy web files and set permissions
    bash code
    ​cp -r /var/www/git/* html chown -R apache:users html​
  • Restart web server to enable the changes
    bash code
    ​/etc/init.d/httpd restart;

Complete

That is it. Navigate to http://gitweb/git to browse the newly created repository.

References

Hosting your own Git Repository on Fedora 12