Setting up a Git Server in Linux

Hello all. I needed to setup a Git server for my team and didn’t want to commit to a paid GitHub account yet. So, I set out to setup a Git server of my own. Instructions are sketchy at best. But, I think I got it to work.

I am using CentOS 5.0 i386.

First, we need to configure Yum to use the RedHat extended Linux repository. For i386 system, run this command:

rpm -Uhv

If you are using a 64bit OS, run this instead:

rpm -Uhv

Then, install Git by running these commands.

yum -y install git
yum -y install git-daemon

Now, we are all set to start the server. First, create a folder that will be the root of all repositories. Let’s say /root/git.

Start Git daemon as follows:

git daemon --reuseaddr --base-path=/root/git --export-all --verbose 
    --enable=receive-pack &

That’s it. If you are running a firewall, drill a hole in port 9418.

Let’s quickly test things out.

We will first create a repository in the server. Recall, we used /root/git as the root of all repositories in the server. So go there and create a folder for a repository.

cd /root/git
mkdir ProjectA
cd ProjectA
git init --bare

OK, now we have a bare repository on the server called “ProjectA”.

Now, go to a client machine. Run these commands to push to the remote repository ProjectA.

mkdir ProjectA
git init
touch README.txt
git add .
git commit -m "Project creation"
git push git://SERVER_IP_OR_HOSTNAME/ProjectA master

This should work and get you in business.

2 thoughts on “Setting up a Git Server in Linux

  1. Your instructions worked perfectly–but then I realized I didn’t want another server. What I need is a remote repository I can push to.

    I want to set-up git on an integration box (redhat) our developers can push to.

    I remember seeing instructions for doing that somewhere, but can’t find them now. I’ll keep looking.

    But for the record, your instructions were awesome.

  2. Pingback: Git | Pepův blog ~

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s