git server setup

For the last decade, I have been using cvs at home to have version control over documents (mostly LaTeX and config files). The original cvs server has been since migrated to a virtual machine.

Note; this is a braindump, the examples below are taken from my bash history and then hand-edited. So do use your own brain when following these steps and leave a comment if you see any editing mistakes

It was about time to move my VCS to git. I bought Version control with Git: powerful techniques for centralized and distributed project management, ISBN 9780596520120, published by O’Reilly and went for it. A braindump of what I did on my RHEL6 server follows. (Big kudos to dgrift for helping me find the mess with git’s homedirectory being set to /var/lib/git see RHBZ #732196 for the problems I had.)

Set up a centralised git server:

[root@server]# yum install git-daemon
[root@server]# useradd -U -Z git_shell_u mygituser -s /usr/libexec/git-core/git-shell git # do NOT set the homedirectory of this user to /var/lib/git if you want to be able to log in with ssh keys.
  • dump ~git/.ssh/authorized_keys with the usual chmod, chown and restorecon
  • make a test repo: [root@server]# cd /var/lib/git [root@server]# mkdir test.git [root@server]# cd test.git [root@server]# git init --bare [root@server]# chown -R git:git /var/lib/git/test.git [root@server]# restorecon -rv /var/lib/git/test.git
  • try working with with it from another box: [user@machine]$ git clone git+ssh:// [user@machine]$ cd test/ [user@machine]$ vi README [user@machine]$ git commit README [user@machine]$ git push origin master

Migrate from cvs:

Read gitcvs-migration and repeat the steps below for all your CVS repos

[user@server]$ mkdir -p ~/tmp/cvs/documents"
[user@server]$ mkdir -p ~/tmp/git/documents"
[user@server]$ cd ~/tmp/cvs/"
[user@server]$ export CVSROOT=":ext:oldcvsuser@old-server:/old/cvs/location/cvsroot"
[user@server]$ export CVS_RSH=ssh #only if you also used ssh before
[user@server]$ cvs -d $CVSROOT checkout documents
[user@server]$ git cvsimport -C /home/pcfe/work/git/documents documents
[root@server]# cd /var/lib/git
[root@server]# mkdir documents-repo.git
[root@server]# cd documents-repo.git
[root@server]# git init --bare
[root@server]# chown -R git:git /var/lib/git/documents-repo.git/
[root@server]# restorecon -rv /var/lib/git/documents-repo.git
[root@server]# git --bare fetch /home/user/tmp/git/documents/ master:master
  • and now for each remaining repo [user@server]$ mkdir -p ~/tmp/cvs/documents" [user@server]$ mkdir -p ~/tmp/git/documents" [user@server]$ cd ~/tmp/cvs/" [user@server]$ cvs -d $CVSROOT checkout SPECS [user@server]$ git cvsimport -C /home/pcfe/work/git/SPECS SPECS [root@server]# cd /var/lib/git/ [root@server]# mkdir SPECS-repo.git [root@server]# chown git.git SPECS-repo.git [root@server]# cd SPECS-repo.git [root@server]# git --bare fetch /home/pcfe/work/git/SPECS/ master:master [root@server]# restorecon -rv /var/lib/git

Verify your backups

Those who do not have a tested backup shall be laughed at. So take this moment to insert a break of a couple days and verify that all your newly created repos in var/lib/git/ end up on your regular backups. And make sure you can successfully restore.

Work with the centralised git repo

Depending on your needs, you might want to Set Up a Git Server through SSH Connection.

To pull it all to your various work machines;

[user@machine]$ mkdir -p ~/work/git/CentralisedRepo</li>
[user@machine]$ cd ~/work/git/CentralisedRepo</li>
[user@machine]$ git clone git+ssh://</li>
[user@machine]$ git clone git+ssh://</li>
# repeat the clone command for each one of your old repos
[user@machine]$ cd SPECS-repo.git</li>
[user@machine]$ vi somefile</li>
[user@machine]$ git commit somefile</li>
[user@machine]$ git push origin</li>

Other things to do with your git server


Máirín Duffy has an excellent writeup on how to use Sparkleshare with Fedora. That the git server runs on RHEL6 is not relevant.