Setting up GIT server on Red Hat Linux

Posted on 30-01-2015 09:22 by graham


This tutorial describes how to install a GIT server on a Linux machine and then connect to it from Windows using GIT command line tool.

Installing GIT

The first thing to do is to install GIT, which can be done with a single command:
yum install git

Configure git user with public keys

First, create a git user:
sudo adduser git
su git
mkdir .ssh && chmod 700 .ssh
touch .ssh/authorized_keys && chmod 600 .ssh/authorized_keys

Now, generate a public key that will be used for authorizing SSH connections:

As a result, two files will be created, one with the public key, and one with the private key. The next thing to do is to append the contents of the public key file to the authorized_keys file:
cat >> ~/.ssh/authorized_keys

Create a GIT repository

Now we will create a GIT repository and make it available through SSH. Let's say the repository will be placed directly under the /home/git directory and will be called projectrepo.
cd /home/git
mkdir projectrepo.git
cd projectrepo.git
git init --bare

That's it, you should now be able to connect to the repository from your local machine.

Connecting to GIT repository using Windows GIT command line tool

First, create a directory where you will "checkout" the GIT repo. Let's say it's called localdir.
cd localdir
git init
git add .
git commit -m 'first commit'

Now we need to tell our local GIT repository what remote repository (called origin) it should connect to. Assuming is the name of our GIT server, we do:
git remote add origin

The next thing to do is to push our local changes to the remove repository:
git push origin master

However, if you try this and you don't have SSH public keys configured on your local machine, you will be prompted for a password. To use SSH public keys mechanism and be able to log in automatically, you need to copy the private and public key files from the server to some directory on your local machine. Usually this will be C:\Users\<username>. Create a directory called C:\Users\<username>\.ssh and upload your key files there.

Next, export the HOME environment variable to point to this home directory:

Then you can test you SSH connection:

and finally push your changes to the repository on the server:
git push origin master


Add comment

Has this tutorial been helpful to you? Or do you see anything wrong? We appreciate your opinion!
Your comment:
Show formatting hints
HTML is disallowed, but in your text you can use the following markup
  • [code][/code] for a block of code
  • [tt][/tt] for inline code
  • [link]link href|link anchor[/link] for links
  • [b][/b] for bold text
+ Ask a question
If you have a technical question related to programming and computers, ask it here. Other users will help you solve it!
Unanswered questions
Share your knowledge by helping others solve their problems