git, gitosis, gitweb on FreeBSD
  Nov 20, 2009

git is an awesome reversion-control system (amougst many other things) Coupled with gitosis for easy user/project/groups/access management and gitweb to get a great visualization of a project's repository, it can quicky scale to any project at hand.

Install git and gitosis

  1. # cd /usr/ports/devel/git
  2. # make config
  3. FreeBSD git makeconfig
  4. # make install clean distclean
  5. # cd /usr/ports/devel/py-gitosis
  6. # make install clean distclean

Installing git creates the git user and specifies /usr/local/git as the home directory. You do not need a password for this new account if you plan to use ssh key authentication... which is also what I will discuss shortly.

Enable sshd

We need sshd enabled if we with to use gitosis and remote-management.

  1. # echo 'sshd_enable="YES"' >> /etc/rc.conf
  2. # /etc/rc.d/sshd start

Generate (ssh) Public Key

CLIENT COMPUTER

Instead of typing in our password everytime we use a git action (which translate into A LOT of times per programming session!), I always like to set up key authentication. We just have to make sure we have a valid key generated for the host we plan to connect from and copy it to the server that contains git to properly setup gitosis.

Make sure you change someuser to a valid ssh user on the server! Also, change server_host to the server's IP or hostname.

  1. $ ssh-keygen -t rsa
  2. $ scp ~/.ssh/id_rsa.pub someuser@server_host:~/client_id_rsa.pub

Initialize gitosis with Public Key

SERVER COMPUTER
  1. # cd /usr/ports/security/sudo
  2. # make install clean distclean
  3. # rehash
  4. # sudo -H -u git gitosis-init < ~someuser/client_id_rsa.pub
  5. Initialized empty Git repository in /usr/local/git/repositories/gitosis-admin.git/
  6. Reinitialized existing Git repository in /usr/local/git/repositories/gitosis-admin.git/
  7. # rm ~someuser/client_id_rsa.pub

Test gitosis-admin.git Repository Access

CLIENT COMPUTER

The following test will let us easily edit the gitosis-admin config file from any computer and verify that you have setup the previous steps correctly.

  1. $ mkdir ~/gitness
  2. $ cd ~/gitness
  3. $ git clone git@server_name:gitosis-admin.git
  4.    Initialized empty Git repository in /home/dfoo/gitness/gitosis-admin/.git/
  5.    remote: Counting objects: 5, done.
  6.    remote: Compressing objects: 100% (4/4), done.
  7.    remote: Total 5 (delta 0), reused 5 (delta 0)
  8.    Receiving objects: 100% (5/5), done.
  9. $ cd gitosis-admin
  10. $ vim gitosis.conf
  11. [gitosis]
  12. gitweb = no
  13.  
  14. [group admins]
  15. writable = gitosis-adminv
  16. members = epoxy@wind
  17.  
  18. [group team1]
  19. writable = test_project
  20. members = @admins user@anotherhost
  21.  
  22. [repo gitosis-admin]
  23. gitweb = no
  24. description = gitosis config files
  25. owner = lyle@digitalfoo.net
  26. members = @admins
  27.  
  28. [repo test_project]
  29. gitweb = yes
  30. description = my first test repo
  31. owner = lyle@digitalfoo.net
  32. members = @team1
  33. $ git add gitosis.conf
  34. $ git commit -m 'gitosis config init'
  35. $ git push
  36. Counting objects: 5, done.
  37. Delta compression using up to 2 threads.
  38. Compressing objects: 100% (3/3), done.
  39. Writing objects: 100% (3/3), 459 bytes, done.
  40. Total 3 (delta 0), reused 0 (delta 0)
  41. WARNING:gitosis.gitweb.set_descriptions:Cannot find 'test_project' in '/usr/local/git/repositories'
  42. WARNING:gitosis.gitweb.generate_projects_list:Cannot find 'test_project' in '/usr/local/git/repositories'
  43. To git@digitalfoo.net:gitosis-admin.git
  44.     b407dca..5faaf3b master -> master

It is ok that we get WARNING messaged in the push. We are about to create these repositories.

CLIENT COMPUTER (still)
  1. $ cd ~/gitness
  2. $ mkdir test_project
  3. $ cd test_project
  4. $ git init
  5. $ git remote add origin git@dserver:test_project.git
  6. $ echo 'this is a test, only a test!' > tester.txt
  7. $ git add tester.txt
  8. $ git commit -m 'added tester.txt'
  9. [master (root-commit) 4b1e0c1] added tester
  10. 1 files changed, 1 insertions(+), 0 deletions(-)
  11. create mode 100644 tester
  12. $ git push origin master:refs/heads/master
  13. Initialized empty Git repository in /usr/local/git/repositories/test_project.git/
  14.  
  15. Counting objects: 3, done.
  16. Writing objects: 100% (3/3), 218 bytes, done.
  17. Total 3 (delta 0), reused 0 (delta 0)
  18. To git@gitty.digitalfoo.net:test_project.git
  19. * [new branch]     master -> master

Install gitweb

SERVER (root)
  1. # cd /usr/ports/www/apache22
  2. # echo 'apache22_enable="YES"' >> /etc/rc.conf
  3. # mkdir /usr/local/www/apache22/data/gitweb
  4. # ln -s /usr/local/www/apache22/data/gitweb /usr/local/www/gitweb
  5. # cp /usr/local/share/examples/git/gitweb/* /usr/local/www/gitweb
  6. # htpasswd -c /usr/local/www/apache22/.htpasswd-gitty.digitalfoo.net gitweb_admin
  7. New password:
  8. Re-type new password:
  9. Adding password for user gitweb_admin

Setup gitweb

  1. # vi /usr/local/etc/gitweb.conf
  2. GIT = "/usr/local/bin/git";
  3. $site_name = "gitty.digitalfoo.net";
  4. $my_uri = "http://gitty.digitalfoo.net";
  5. $projects_list = "/usr/local/git/gitosis/projects.list";
  6. $projectroot = "/usr/local/git/repositories";
  7.  
  8. #$git_temp = "/tmp";
  9. #$home_link = $my_uri;
  10. #$home_text = "indextext.html";
  11. #$projects_list = $projectroot;
  12. #$stylesheet = "/gitweb/gitweb.css";
  13. #$logo = "/gitweb/git-logo.png";
  14. #$favicon = "/gitweb/git-favicon.png";
  15. $projects_list_description_width = 40;
  16.  
  17. #$feature{'pathinfo'}{'default'} = [1];
  18.  
  19. $feature{'search'}{'default'} = [undef];
  20. $feature{'blame'}{'default'} = [undef];
  21. $feature{'pickaxe'}{'default'} = [undef];
  22. $feature{'grep'}{'default'} = [undef];
  23.  
  24. # $prevent_xss = true

Apache VHOST Config

  1. htpasswd -c /usr/local/etc/apache22/.htpasswd-gitty.digitalfoo.net web_username
  2. # vi /usr/local/etc/apache22/httpd.conf
  3. --- --- snip --- snip --- ---
  4. ServerAdmin lyle@digitalfoo.net
  5. --- --- snip --- ---
  6. # Virtual hosts
  7. Include etc/apache22/extra/httpd-vhosts.conf
  8. # vi /usr/local/etc/apache22/extra/http-vhosts.conf
  9. --- snip --- snip --- snip ---
  10. # gitty.digitalfoo.net
  11. <VirtualHost *:80>
  12.     ServerName gitty.digitalfoo.net
  13.     DocumentRoot "/home/git/gitweb"
  14.  
  15.     #ScriptAlias /cgi-bin/ "/home/git/gitweb/cgi-bin/"
  16.  
  17.     <Directory "/home/git/gitweb">
  18.         Options Indexes FollowSymlinks ExecCGI
  19.         AllowOverride None
  20.         Order allow,deny
  21.         Allow from all
  22.         <Files gitweb.cgi>
  23.             SetHandler cgi-script
  24.         </Files>
  25.  
  26.         AuthName "teh c0dez"
  27.         AuthType Basic
  28.         AuthUserFile /usr/local/etc/apache22/.htpasswd-gitty.digitalfoo.net
  29.         Require valid-user
  30.     </Directory>
  31.  
  32. DirectoryIndex gitweb.cgi
  33. SetEnv GITWEB_CONFIG /usr/local/etc/gitweb.conf
  34. </VirtualHost>
  35. # apachectl restart

Allow Webserver Access to gitweb / Repositories

  1. $ cd /usr/local/git/repositories
  2. # pw groupmod www -m git
  3. $ chgrp www /usr/local/git/repositories
  4. $ chgrp www /usr/local/git/repositories/*

Miscellaneous Information

Set Name and E-mail

To make commits show up with your (unique!) name attached to them, rather then generic names that are set by git itself, run the following commands as the user you will be git pushing from.

  1. $ git config --global user.name "Your Name Comes Here"
  2. $ git config --global user.email you@yourdomain.example.com

Adding a New Repository

CLIENT COMPUTER

First off, if you have not git clone'ed gitosis-admin.git, do it now:

  1. mkdir ~/gitness
  2. cd ~/gitness
  3. $ git clone git@server_name:gitosis-admin.git
  4.    Initialized empty Git repository in /home/dfoo/gitness/gitosis-admin/.git/
  5.    remote: Counting objects: 5, done.
  6.    remote: Compressing objects: 100% (4/4), done.
  7.    remote: Total 5 (delta 0), reused 5 (delta 0)
  8.    Receiving objects: 100% (5/5), done.

Give a user or group write (or read!) access to the new repository and set up the actual config for the new repository.

  1. $ cd ~/gitness/gitosis-admin
  2. $ vim gitosis.conf
  3. --- --- snip --- ---
  4. [group team1]
  5. - writable = test_project
  6. + writable = test_project new_project
  7. --- --- snip --- ---
  8. [repo new_project]
  9. gitweb = yes
  10. description = short description of project
  11. owner = user@somedomain.com
  12. members = @team1
  13. $ git add gitosis.conf
  14. $ git commit -m 'added new_project repo'
  15. $ git push

Initialize a New git Project

Now that we have the new repository setup in gitosis, it's time to create the project files on the client computer and push them to the server as needed.

  1. $ mkdir ~/gitness/new_project
  2. $ cd ~/gitness/new_project
  3. $ git init
  4. $ git remote add origin git@dserver:new_project.git
  5. $ touch TODO
  6. $ git add TODO
  7. $ git commit -m 'new_project repo init'
  8. $ git push origin master:refs/heads/master

From now on, you should be able to fetch the files with git clone (supposing your host is allowed via gitosis) and will be able to simply use git push after a commit instead of the longer push we just did.

Add More Remote Users




Post a New Comment

Name

Message

Security
Code

        (case insensitive & space between words)


Posted Comments
anonymous  Nov 11, 2011
KnyCHivE <a href="http://www.wnyfunrun.org">cheap ugg boots uk</a> KbfWUcrE <a href=http://www.wnyfunrun.org>ugg boots for cheap</a> RzpMPqzR http://www.wnyfunrun.org