Hosting your own Git Repositories
While some of the Git-based services out there are very cool, especially the social aspects of them. However, if you are working on your own projects by yourself or with a very small team and need “private” repositories, why spend the money on one of these services? With hosting being what it is today, it’s extremely affordable to have root-access to your own Server and not be with a host that completely sucks. Or, you can turn that old windows machine that is collecting dust in the corner into your own Git Server running CentOS or Ubuntu.
Assuming you know some command line, and a bit about Linux (focusing on CentOS here), you can be up and running with a Git Server & Redmine in no time!
Log into your remote machine, sudo or su to root:
yum install gettext-devel expat-devel curl-devel zlib-devel openssl-devel
cd /tmp
wget http://www.codemonkey.org.uk/projects/git-snapshots/git/git-latest.tar.gz
tar zxvf git-latest.tar.gz
cd git-date_of_snapshot
autoconf
./configure --with-curl=/usr/local
make && make install
Okay, so now we have Git installed on our machine. To make sure things are good, type:
which git
and it should give you “/usr/local/bin/git”
Now, to add the Git user:
First, we need to add the git-shell to /etc/shells, so you can use ssh to pull from and push to your git repositories, but no shell access is allowed.
vim /etc/shells
Add the following at the end of the file:
/usr/local/bin/git-shell
Write/Quit the file, and let’s get on making the user.
useradd -s /usr/local/bin/git-shell git
passwd git
SSH Keys
We should add ssh keys so we don’t have to type our password in every time we push or pull to our repositories. If you already have your ssh key, you will find it in ~/.ssh/id_rsa.pub So on our local machine we will be deploying from, open your terminal and:
cd .ssh
ssh-keygen -tdsa -f./id_dsa
You will be prompted for a passphrase, for this, you can just leave it blank. Now:
chmod 600 id_dsa*
cat id_dsa
Copy the output in your terminal, go to the remote machine and:
cd /home/git/.ssh // If the directory doesn't exist, create it
vim authorized_keys // copy the output from your local id_dsa key in this file
chmod 400 authorized_keys
cd ../ && chown -R git:git .ssh
To test this, try to shell to the machine as your git user. You should get a rejection message b/c it’s a “git-shell.” Really, we just don’t want to be prompted for the password.
Make your Git Repository
Now comes the fun part, make your first repository. On the remote machine, as root:
cd /home/git
mkdir myrepo.git && cd myrepo.git
git --bare init
cd ../
chown -R git:git myrepo.git
Then, on your local machine:
git clone git@your_domain.com:myrepo.git
Again, we shouldn’t get prompted for the password, if you are still having problems, google will have answers. ![]()
I hope this is helpful, next time, I’ll go over managing your project with Redmine, a rails app that is very nice.
on December 07, 2009 at 12:54 pm
on December 06, 2009 at 3:57 pm
on March 10, 2009 at 7:23 am
on December 07, 2008 at 3:07 am
on December 07, 2008 at 3:04 am
on June 30, 2008 at 2:48 pm
on June 27, 2008 at 5:01 pm