Install Git on Your Private RHEL or CentOS Server

If you don’t use RHEL or CentOS, or if Git is already installed on your server, please skip ahead. First, install the appropriate EPEL repository on your server:

curl -O
yum --nogpgcheck install epel-release-5-4.noarch.rpm

Next, install Git:

yum install git

Create a Bare Clone of the Existing Repository

From your local machine:

git clone --bare ./project.git

A bare repository is one without a working copy of the code: it only contains the repository’s Git database. A bare repository on the server will prevent you from accidentally introducing working copy conflicts.

Copy the Bare Repository to Your Private Server

From your local machine:

tar cvfz project.tgz project.git/
scp project.tgz user@hostname:project.tgz
ssh user@hostname

From your server:

adduser git
mv project.tgz /home/git/
cd /home/git/
tar xvfz project.tgz
rm project.tgz

Configure SSH+Git Permissions

From your server:

chmod g+rx /home/git
usermod -a -G git user
chown -R git:git project.git/
cd project.git/
git --bare init --shared=group
chmod g+ws branches hooks info objects objects/* refs

Clone a New Working Copy from Your Private Server

From your local machine:

git clone ssh://user@host/home/git/project.git

Update “Origin” of Existing Working Copies

From your local machine:

git remote rm origin`
git remote add origin ssh://user@host/home/git/project.git`