freebsd + git server + gitweb
1. install git server
$ cd /usr/ports/devel/git $ make install clean |
Note: Include gitweb as an option
2. Modify /etc/rc.conf
git_daemon_enable="YES" git_daemon_directory="/var/db/git/repo" git_daemon_flags="--export-all --syslog --enable=receive-pack --listen=ip_address --verbose" |
3. Create git user
$ pw user add git $ passwd git $ chsh git Login: git Password: ******************* Uid [#]: 1002 Gid [# or name]: 1002 Change [month day year]: Expire [month day year]: Class: Home directory: /var/db/git Shell: /usr/local/bin/git-shell Full Name: User & Office Location: Office Phone: Home Phone: Other information: |
“git” user would create repositories. We could also add “rupert” to the git group.
pw user mod rupert -G git |
4. Let’s create a repository
$ cd /var/db/git/repo $ sudo mkdir cws-rails.git $ cd cws-rails.git/ $ sudo git --bare init Initialized empty Git repository in /var/db/git/repo/cws-rails.git/ $ cd .. $ ls -l total 4 drwxr-xr-x 7 root git 512 Nov 16 12:54 cws-rails.git drwxrwxr-x 7 git git 512 Nov 16 11:52 myproject.git $ sudo chown -Rf git:git cws-rails.git $ sudo chmod -Rf 775 cws-rails.git |
Make sure to change the ownership to git. We also make it writable to the group so users like rupert will have write access.
5. Let’s clone, commit and push
So now in my MBP, i will clone myproject.git, change some file and push.
$ git clone rupert@rupert-bsd:/var/db/git/repo/myproject.git Cloning into myproject... Password: remote: Counting objects: 12, done. remote: Compressing objects: 100% (9/9), done. remote: Total 12 (delta ), reused (delta ) Receiving objects: 100% (12/12), done. |
~/Desktop/myproject[master]% gc -m "Updated CHANGELOG" CHANGELOG [master d9fd0f7] Updated CHANGELOG 1 files changed, 1 insertions(+), deletions(-) ~/Desktop/myproject[master]% git push Password: Counting objects: 5, done. Delta compression using up to 2 threads. Compressing objects: 100% (3/3), done. Writing objects: 100% (3/3), 332 bytes, done. Total 3 (delta 1), reused (delta ) To rupert@rupert-bsd:/var/db/git/repo/myproject.git 5d16498..d9fd0f7 master -> master |
Note: So that we don’t need to specify the password all the time, generate an ssh-keygen -t rsa for id_rsa.pub and append it to rupert@rupert-bsd:/home/rupert/.ssh/authorized_keys
6. Setup Git, Configure and Restart Apache2
# Copy the gitweb directory to your apache22 directory $ sudo cp -Rf /usr/local/share/examples/git/gitweb /usr/local/www/apache22/data/ # Edit gitweb.cgi to point to your repo $ vim /usr/local/www/apache22/data/gitweb/gitweb.cgi our $projectroot = "/var/db/git/repo"; |
# Allow apache to execute gitweb.cgi Alias /gitweb /usr/local/www/apache22/data/gitweb <Directory /usr/local/www/apache22/data/gitweb> Options FollowSymLinks +ExecCGI AddHandler cgi-script .cgi </Directory> |
Browse http://servername/gitweb/gitweb.cgi