How to configure Git Server in Centos-6..& RHEL-6.. What Is Git ?

What Is Git ?

It is a very popular and efficient open source Version Control System. It tracks content such as files and directories.
It stores the file content in BLOBs (binary large objects). The folders are represented as trees.
More Info..BLOBS- Click
How to install own git server with ssh and http access by using gitolite and gitweb in Linux.
For user management in Git Server.

I'm Creating a private git server. And can be accesible through ssh and http both.Here Gitweb
will be used for viewing repositories detail. Gitolite is used for Git server with user/group management.
What is Git Web ? 
Gie Eb used for viewing git repositories detail via Web Browser.

What Is Gitolite ?
It is an access control layer on top of git.

Git Server System Details-

Operating System-   Centos-6.4
Packages-     Apache (httpd), Gitolite and Gitweb
Server IP-
Client IP-
Server Hostname-

Configure Git Server Use below Step by Step-...

Step-1 Login Your Git Server PC and configure or change hostname & entry in FQDN.. (

1- Change Ip Address

[root@server ~]# vim /etc/sysconfig/network-script/ifcfg-eth0


2- Change Hostname

[root@server ~]# vim /etc/sysonfig/network

[root@server ~]# vim /etc/hosts   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6         server


3- Restart Network Services..

[root@server ~]# service network restart

4- Check Hostname..

[root@server ~]# hostname

5- Check IP..

[root@server ~]# ifconfig

Step-2 Login Client PC

Login into your linux pc from where you want to manage git server remotely .
Means here I am talking about your client system..

1- Create RSA Key..

[ashu@client ~]$ ssh-keygen -t rsa -C "Git-Admin"

Now Sucessfully create RSA Key..

2- Copy the pub key ( to the */tmp* directory on our Git Server.

[ashu@client ~]$ scp ~/.ssh/ root@

Note- (ip-address-of-git-server)

Step-3 Login Git Server PC..and Gitolite Installation

1- Install the following dependency packages..

[root@server ~]# yum -y install git httpd perl-Time-HiRes

2- Create user git and change its gid and uid

[root@server ~]# useradd git
[root@server ~]#usermod -u 600 git
[root@server ~]# groupmod -g 600 git

3- Move the pub key of Git-Admin user that we have created above from */tmp* and set the appropriate permission.
[root@server ~]# mv /tmp/ /home/git/

[root@server ~]# chown git:git /home/git/

4- Login with user git directly from terminal.Do not set password for user git. And git clone the
gitolite from

[root@server ~]# su -l git
[git@server ~]$ whoami


[git@server ~]$ echo $HOME


5- Now clone the gitolite repository from github.

[git@server ~]$  git clone git://
[git@server ~]$ git clone

6- Create bin directory in /home/git and setup the Git-Admin account

[git@server ~]$ mkdir -p /home/git/bin

7- Installing and Setting up of Gitolite environment.

[git@server ~]$ gitolite/install -ln
[git@server ~]$ gitolite setup -pk

8- Exit from user git login and again use the user root. Now check what are values defined for
suexec bydefault. Use the command suexec -V

[git@server ~]$ exit
[root@server ~]# suexec -V

9- Create a directory bin under /var/www (Web Server Root) as per *suexec* output and set the appropriate permission.

[root@server ~]# install -d -m 0755 -o git -g git /var/www/bin

10- Now create (bash script) with following content under /var/www/bin.

[root@server ~]# vim /var/www/bin/

# Suexec wrapper for gitolite-shell
export GIT_PROJECT_ROOT="/home/git/
export GITOLITE_HTTP_HOME="/home/git"

wq:!  (Save & Quit)

11- Set the appropriate permission.

[root@server ~]# chown -R git:git /var/www/bin

[root@server ~]# chmod 750 /var/www/bin/

[root@server ~]# chmod 755 /var/www/bin

12- Now modify the UMASK value in /home/git/.gitolite.rc.

[root@server ~]# vim /home/git/.gitolite.rc
UMASK => 0077
UMASK => 0027

Step-4 Now Installing GitWeb....

1- Install gitweb package

[root@server ~]# yum install gitweb -y

Note- By default gitweb is installed at /var/www/git.

2- Rename the git directory (under /var/www/git) to *gitweb* and change the ownership to git.

[root@server ~]# mv /var/www/git /var/www/html/gitweb
[root@server ~]#  chown -R git:git /var/www/html/gitweb

3- Modify the value of $projectroot and $projects_list in gitweb conf file (/etc/gitweb.conf) and set the same value in/var/www/html/gitweb/gitweb.cgifile.

[root@server ~]# vi /etc/gitweb.conf

our $projectroot = "/home/git/repositories/";
our $projects_list = "/home/git/projects.list";

[root@server ~]# vi /var/www/html/gitweb/

our $projectroot = "/home/git/repositories";
our $projects_list = "/home/git/projects.list";

4- Now create a dummy folder git and set the appropriate permission.

[root@server ~]# install -d -m 0755 -o apache -g apache /var/www/git

5- Now Configure apache ...

[root@server ~]# vi /etc/httpd/conf/httpd.conf


# You can comment out the below 3 lines and put correct value as per your
server information
ServerAlias server
DocumentRoot /var/www/git

Options None
AllowOverride none
Order allow,deny
Allow from all

SuexecUserGroup git git
ScriptAlias /git/ /var/www/bin/
ScriptAlias /gitmob/ /var/www/bin/

AuthType Basic
AuthName "Git Access"
Require valid-user
AuthUserFile /etc/httpd/conf/git.passwd

:wq! (Save & Quit)

6- Now update the gitweb apache conf file /etc/httpd/conf.d/git.conf.

[root@server ~]# vim /etc/httpd/conf.d/git.conf

Alias /gitweb /var/www/html/gitweb

Options +ExecCGI
AddHandler cgi-script .cgi
DirectoryIndex gitweb.cgi

AuthType Basic
AuthName "Git Access"
Require valid-user
AuthUserFile /etc/httpd/conf/git.passwd


:wq! (Save & Quit)

7- We will create Apache Basic auth username and password using *htpasswd*.

[root@server ~]# htpasswd -c /etc/httpd/conf/git.passwd admin

[root@server ~]# htpasswd /etc/httpd/conf/git.passwd userxyz1

[root@server ~]# htpasswd /etc/httpd/conf/git.passwd userxyz2

Note: We used first time -c flag to create new password file (/etc/httpd/conf/git.passwd).

8- Restart the Apache Web service and enable it to autostart in runlevel (3 & 5) during system startup.

[root@server ~]# service httpd restart

[root@server ~]# chkconfig httpd on

9- Disable Iptables ans Selinux...

[root@server ~]# service iptables stop

[root@server ~]# vim /etc/sysconfig/selinux
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
# SELINUXTYPE= can take one of these two values:
#     targeted - Targeted processes are protected,
#     mls - Multi Level Security protection.

10- Verify the GitWeb is running fine using your favorite browser.
http://(ip-address OR FQDN) of git-server/gitweb/

Step-5 Go To Clien PC and Verify that you are able to clone the git using http from Client Machine.

$ mkdir ~/git-repo/
$ cd ~/git-repo
$ git clone git@

Note- ip is a Server IP Address..

Step-6  Manage user and group of Git Server (from remote client Machine).

1- To manage Git user and groups on Git-Server, we need to clone the gitolite-admin repo.

$ cd ~/git-repo
$ git config --global "Git-Admin"
$ git config --global ""
$ git clone git@

2- Adding new users and repos (Client Machine).

First, obtain pubkeys for your users. We will start with the example users user-1 and user-2.
Ask both of them to generate a keypair just as we did in upper most section of this doc., and send you their keys somehow.
Save them with their respective names ( and in /tmp of your workstation.
Now you have your two users, let us assume that your two new repos are dev and prod. The dev repo must be
writeable by user-1, but read-only to user-2. The prod repo is the other way around writeable by user-2, read-only to user-1.
Now, on on your client machine under gitolite-admin/keydir copy the pub keys of user-1 and user-2:
$ cd ~/git-repo/gitolite-admin
$ cp /tmp/ /tmp/ keydir


3- Now we need to update the gitolite conf file (gitolite.conf).

$ vim conf/gitolite.conf
repo gitolite-admin
RW+ = sena
repo testing
RW+ = @all
repo dev
RW = user-1
R =  user-2
repo prod
RW = user-2
R = user-1 

:wq! (Save & Quit)

Note: R is for Read and W is for Write.

4- Now we need to push the changes of gitolite.conf to Git Server.

$ git add keydir conf

$ git commit -m 'added users user-1 and user-2, repos dev and prod'
[master 4932ca2] added users user-1 and user-2, repos dev and prod
3 files changed, 10 insertions(+), 0 deletions(-)
create mode 100644 keydir/
create mode 100644 keydir/

$ git push origin master
Counting objects: 11, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (6/6), done.
Writing objects: 100% (7/7), 1.21 KiB, done.
Total 7 (delta 0), reused 0 (delta 0)
remote: Initialized empty Git repository in /home/git/repositories/
remote: Initialized empty Git repository in
To git@
7dd3afe..4932ca2 master -> master

Step-7 Creating repository on Git Server..

1- Login in Git Server as root.And then change to git user.

[root@server ~]#  su -l git

$ cd repositories
$ mkdir test-repo.git
$ cd test-repo.git
$ git --bare init
$ git update-server-info

Step- 8 Some Usefull Git Command..

1- Setting up of Git Environment variable.

$ git config --global ""
$ git config --global "Your Name"
$ git config --global core.editor "vim"
$ git clone gitolite@GitServerIP-or-FQDN:d

2- Adding file1 in Git.

$ git add file1
$ git commit -m "Adding file1"
$ git push origin master

3- Deleting file in Git.

$ rm file1
$ git commit -m "Removing file file1"
$ git push origin master

4- Sync the file to local File System from Git Server if someone deleted file locally.

$ git reset --hard
$ git checkout filename

5- Pull the already created git repo from Git Server.

$ git clone gitolite@GitServerIP-or-FQDN:o
$ cd ops
$ git pull


I Hope You Like It..
So Enjoy...

Click Back..                                Click Home..