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
- # cd /usr/ports/devel/git
- # make config
-
- # make install clean distclean
- # cd /usr/ports/devel/py-gitosis
- # 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.
- # echo 'sshd_enable="YES"' >> /etc/rc.conf
- # /etc/rc.d/sshd start
Generate (ssh) Public Key
CLIENT COMPUTERInstead 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.
- $ ssh-keygen -t rsa
- $ scp ~/.ssh/id_rsa.pub someuser@server_host:~/client_id_rsa.pub
Initialize gitosis with Public Key
SERVER COMPUTER- # cd /usr/ports/security/sudo
- # make install clean distclean
- # rehash
- # sudo -H -u git gitosis-init < ~someuser/client_id_rsa.pub
- Initialized empty Git repository in /usr/local/git/repositories/gitosis-admin.git/
- Reinitialized existing Git repository in /usr/local/git/repositories/gitosis-admin.git/
- # rm ~someuser/client_id_rsa.pub
Test gitosis-admin.git Repository Access
CLIENT COMPUTERThe 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.
- $ mkdir ~/gitness
- $ cd ~/gitness
- $ git clone git@server_name:gitosis-admin.git
- Initialized empty Git repository in /home/dfoo/gitness/gitosis-admin/.git/
- remote: Counting objects: 5, done.
- remote: Compressing objects: 100% (4/4), done.
- remote: Total 5 (delta 0), reused 5 (delta 0)
- Receiving objects: 100% (5/5), done.
- $ cd gitosis-admin
- $ vim gitosis.conf
- [gitosis]
- gitweb = no
- [group admins]
- writable = gitosis-adminv
- members = epoxy@wind
- [group team1]
- writable = test_project
- members = @admins user@anotherhost
- [repo gitosis-admin]
- gitweb = no
- description = gitosis config files
- owner = lyle@digitalfoo.net
- members = @admins
- [repo test_project]
- gitweb = yes
- description = my first test repo
- owner = lyle@digitalfoo.net
- members = @team1
- $ git add gitosis.conf
- $ git commit -m 'gitosis config init'
- $ git push
- Counting objects: 5, done.
- Delta compression using up to 2 threads.
- Compressing objects: 100% (3/3), done.
- Writing objects: 100% (3/3), 459 bytes, done.
- Total 3 (delta 0), reused 0 (delta 0)
- WARNING:gitosis.gitweb.set_descriptions:Cannot find 'test_project' in '/usr/local/git/repositories'
- WARNING:gitosis.gitweb.generate_projects_list:Cannot find 'test_project' in '/usr/local/git/repositories'
- To git@digitalfoo.net:gitosis-admin.git
- 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)- $ cd ~/gitness
- $ mkdir test_project
- $ cd test_project
- $ git init
- $ git remote add origin git@dserver:test_project.git
- $ echo 'this is a test, only a test!' > tester.txt
- $ git add tester.txt
- $ git commit -m 'added tester.txt'
- [master (root-commit) 4b1e0c1] added tester
- 1 files changed, 1 insertions(+), 0 deletions(-)
- create mode 100644 tester
- $ git push origin master:refs/heads/master
- Initialized empty Git repository in /usr/local/git/repositories/test_project.git/
- Counting objects: 3, done.
- Writing objects: 100% (3/3), 218 bytes, done.
- Total 3 (delta 0), reused 0 (delta 0)
- To git@gitty.digitalfoo.net:test_project.git
- * [new branch] master -> master
Install gitweb
SERVER (root)- # cd /usr/ports/www/apache22
- # echo 'apache22_enable="YES"' >> /etc/rc.conf
- # mkdir /usr/local/www/apache22/data/gitweb
- # ln -s /usr/local/www/apache22/data/gitweb /usr/local/www/gitweb
- # cp /usr/local/share/examples/git/gitweb/* /usr/local/www/gitweb
- # htpasswd -c /usr/local/www/apache22/.htpasswd-gitty.digitalfoo.net gitweb_admin
- New password:
- Re-type new password:
- Adding password for user gitweb_admin
Setup gitweb
- # vi /usr/local/etc/gitweb.conf
- GIT = "/usr/local/bin/git";
- $site_name = "gitty.digitalfoo.net";
- $my_uri = "http://gitty.digitalfoo.net";
- $projects_list = "/usr/local/git/gitosis/projects.list";
- $projectroot = "/usr/local/git/repositories";
- #$git_temp = "/tmp";
- #$home_link = $my_uri;
- #$home_text = "indextext.html";
- #$projects_list = $projectroot;
- #$stylesheet = "/gitweb/gitweb.css";
- #$logo = "/gitweb/git-logo.png";
- #$favicon = "/gitweb/git-favicon.png";
- $projects_list_description_width = 40;
- #$feature{'pathinfo'}{'default'} = [1];
- $feature{'search'}{'default'} = [undef];
- $feature{'blame'}{'default'} = [undef];
- $feature{'pickaxe'}{'default'} = [undef];
- $feature{'grep'}{'default'} = [undef];
- # $prevent_xss = true
Apache VHOST Config
- htpasswd -c /usr/local/etc/apache22/.htpasswd-gitty.digitalfoo.net web_username
- # vi /usr/local/etc/apache22/httpd.conf
- --- --- snip --- snip --- ---
- ServerAdmin lyle@digitalfoo.net
- --- --- snip --- ---
- # Virtual hosts
- Include etc/apache22/extra/httpd-vhosts.conf
- # vi /usr/local/etc/apache22/extra/http-vhosts.conf
- --- snip --- snip --- snip ---
- # gitty.digitalfoo.net
- <VirtualHost *:80>
- ServerName gitty.digitalfoo.net
- DocumentRoot "/home/git/gitweb"
- #ScriptAlias /cgi-bin/ "/home/git/gitweb/cgi-bin/"
- <Directory "/home/git/gitweb">
- Options Indexes FollowSymlinks ExecCGI
- AllowOverride None
- Order allow,deny
- Allow from all
- <Files gitweb.cgi>
- SetHandler cgi-script
- </Files>
- AuthName "teh c0dez"
- AuthType Basic
- AuthUserFile /usr/local/etc/apache22/.htpasswd-gitty.digitalfoo.net
- Require valid-user
- </Directory>
- DirectoryIndex gitweb.cgi
- SetEnv GITWEB_CONFIG /usr/local/etc/gitweb.conf
- </VirtualHost>
- # apachectl restart
Allow Webserver Access to gitweb / Repositories
- $ cd /usr/local/git/repositories
- # pw groupmod www -m git
- $ chgrp www /usr/local/git/repositories
- $ 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.
- $ git config --global user.name "Your Name Comes Here"
- $ git config --global user.email you@yourdomain.example.com
Adding a New Repository
CLIENT COMPUTERFirst off, if you have not git clone'ed gitosis-admin.git, do it now:
- mkdir ~/gitness
- cd ~/gitness
- $ git clone git@server_name:gitosis-admin.git
- Initialized empty Git repository in /home/dfoo/gitness/gitosis-admin/.git/
- remote: Counting objects: 5, done.
- remote: Compressing objects: 100% (4/4), done.
- remote: Total 5 (delta 0), reused 5 (delta 0)
- 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.
- $ cd ~/gitness/gitosis-admin
- $ vim gitosis.conf
- --- --- snip --- ---
- [group team1]
- - writable = test_project
- + writable = test_project new_project
- --- --- snip --- ---
- [repo new_project]
- gitweb = yes
- description = short description of project
- owner = user@somedomain.com
- members = @team1
- $ git add gitosis.conf
- $ git commit -m 'added new_project repo'
- $ 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.
- $ mkdir ~/gitness/new_project
- $ cd ~/gitness/new_project
- $ git init
- $ git remote add origin git@dserver:new_project.git
- $ touch TODO
- $ git add TODO
- $ git commit -m 'new_project repo init'
- $ 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
- Tags
- AI (1)
- ALIX (1)
- digitalfoo.net (2)
- embedded (6)
- FreeBSD (30)
- Java (1)
- Linux (26)
- misc (7)
- my projects (1)
- MySQL (2)
- NanoBSD (3)
- opensource (7)
- perl (1)
- PHP (3)
- programming (11)
- Python (1)
- security (4)
- Archives
- 2011
- February (1)
- March (1)
- June (1)
- July (1)
- August (1)
- 2010
- June (5)
- July (2)
- December (4)
- April (6)
- March (2)
- May (1)
- August (2)
- October (1)
- November (1)
- 2009
- August (7)
- July (8)
- April (4)
- May (4)
- December (2)
- June (1)
- September (1)
- November (4)
- October (1)
- Web Tools
- Index
- dig-shovel Live
- SQL Injection Encoder
- Links
-

