Latest technology news, trends and developers guide for business application. Visit this space for more tech updates.

Let’s work on your exciting new project together!

How to setup git on self hosted server.

iOS9 app development, Cloud Technology, Tech Blog, News

This article discusses setting up Git server on a self-hosted server, e.g. you can buy an AWS EC2 and have your own git environment or you can have your own local server. (

Knowledge Base:

If cost is not an issue, there are multiple services like model is number of repository based) and (Pricing model is based on number of users – up to 5 user it’s all free, you can create n number of repository).

Why we should self-host Git:


  • You can save money by hosting on your local server in your office premise; you just need an Ubuntu or Linux based system!
  • Data transfer speed will be super-fast as it will be on your local network
  • Your data is on your server, so it’s secure!


  • You are managing this in-house, so you may need IT persons to handle ongoing support and maintenance of server
  • If you are hosting on your local network and you need to access outside network you will need static IP and should be pointing to some domain, so static IP may cost something.
  • You will not get smart UI to manage repository, users and its access.

How to setup Local Git!

Steps for how to install Git on Ubuntu 12.04 LTS server, for other version steps are same, but I have tested on this version.

Assuming you have Ubuntu server ready and you are connected using Terminal app in Mac or some SSH tool.

Step #1: Install Git, Apache

$ sudo apt-get install git apache2

Step #2: Create the “git” user/group.

$ sudo adduser git

Fill all required information it asks, make sure you remember password.

Step #3: Setup Client Machine to manage Git Repos

  • Client machine is from where you will be remotely managing Git repositories, mostly an IT Admin’s PC.
  • Make sure it’s a Linux machine, ssh-keygen is already installed, and it came by default with Mac machine.
  • Create RSA key without passphrase which is identity of your machine.

This command should have created 2 files “id_rsa” and “” under $HOME/.ssh directory.

PS: If you would like to manage repository from other PCs later, you may need to share this key with new machine, feel free to contact me in case of trouble , I will be happy to help.

Copy “” file to your remote Ubuntu server which we are setting up as Git Server.

KB: scp is command to copy file on remote server, this command will copy “” file from Client Machine to Remote server. Make sure this command is fired on Client Machine 🙂

Step #4: Setup Git Admin

Switch back from Terminal to remote server!

Move and Rename pub key file to proper location now and also set owner to git group and user.

$ sudo mv /tmp/ /home/git/
$ sudo chown git:git /home/git/

Step #5: Login as git user

Login as git user now, $ su -l git

Step #6: Gitolite installation

Gitolite is a tool to manage Git repos.

#1: Checkout source from github.

$ git clone

#2: Create bin folder at /home/git

$ mkdir bin

#3: Install gitolite

$ cd gitolite/
$ ./install
$ cd ..
$ /home/git/gitolite/src/gitolite setup -pk
$ exit

Exit is to logout from git user, now you should be in your root account.

Step #7: Create bin folder to your Web Root and set permission and owner

$ cd /var/www
$ sudo mkdir bin
$ install -d -m 0755 -o git -g git /var/www/bin

Step #9: Scripts for Gitolite

$ cd /var/www/bin
$ sudo vi

Paste below script:

# Suexec wrapper for gitolite-shell

export GIT_PROJECT_ROOT=”/home/git/repositories”
export GITOLITE_HTTP_HOME=”/home/git”

exec ${GITOLITE_HTTP_HOME}/gitolite/src/gitolite-shell

Set Proper permission

$ chown -R git:git /var/www/bin
$ chmod 750 /var/www/bin/
$ chmod 755 /var/www/bin

Step #10: Modify “UMASK”

$ sudo vi /home/git/.gitolite.rc

Change UMASK,

UMASK => 0077

UMASK => 0027

Step #11: Clone Gitolite Admin repo to Client Machine

PS: Switch to your Client Machine terminal

$ mkdir ~/git-repos
$ cd ~/git-repos
$ git clone git@ip-address-of-git-server:gitolite-admin.git

Step #12:
Adding new users and repos

Get pubkeys for your users

For example users “jaym” and “zaidp”.

Let’s create keys for “jaym” and “zaidp”

Make sure you create without passphrase

$ ssh-keygen -t rsa -C “Creating jaym keys” -f “jaym”
$ ssh-keygen -t rsa -C “Creating zaidp keys” -f “zaidp”

PS: keys will be generated in the same directory you are now in, it won’t create in ~/.ssh folder as you have provided -f parameter in command

KB: this time we have used -f param to specify file name of keys, if we don’t provide -f it will generate with id_rsa name only.

$ cp ~/git-repos/gitolite-admin/keydir

Let’s create repository now, we will creating 3 repos

  • “foo” : only jaym will have Read/Write access and zaidp will have only Read
  • “bar” : only zaidp will have Read/Write access and jaym will have only Read
  • “foobar” : only jaym & zaidp both will Read/Write access

$ cd ~/git-repos/gitolite-admin/
$ vi conf/gitolite.conf

Updated gitolite conf looks like below,

repo gitolite-admin
RW+ = Git-Adm

repo testing
RW+ = @all

repo foo
RW = jaym
R = zaidp

repo bar
R = jaym
RW = zaidp

repo foobar
RW = jaym
RW = zaidp

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

Push changes to server now,

$ git add keydir conf
$ git commit -m ‘added users jaym and zaidp and also created sample repos’
$ git push origin master

Counting objects: 4, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (4/4), 455 bytes | 0 bytes/s, done.
Total 4 (delta 0), reused 0 (delta 0)
remote: Initialized empty Git repository in /home/git/repositories/bar.git/
remote: Initialized empty Git repository in /home/git/repositories/foo.git/
remote: Initialized empty Git repository in /home/git/repositories/foobar.git/
To git@

6a5ee66..d032149 master > master

Step #13:
How Jay and Zaid will be able to use Git

Assuming both are using Mac systems

#1: Send jaym key file to Jay in his Mac
#2: Jay needs to copy that file in ~/.ssh folder.
#3: in same ~/.ssh folder you should be able to find config file, if you cannot find you can create new file named “config”, PS: no extension.
#4: Open config file in any text editor. i.e. textedit, brackets
#5: Paste below line and save & close file.

Host git-jaym
User git
IdentityFile ~/.ssh/jaym
IdentitiesOnly yes

Let’s checkout repo.

#6: Now open terminal app

$ mkdir ~/foo
$ cd ~/foo
$ git clone git@git-jaym:foo.git

Cloning into ‘foo’…
warning: You appear to have cloned an empty repository.
Checking connectivity… done.

So that’s it! Jay is successfully able to checkout foo repo, we can do the same for other repo and other users!

You can also use Sourcetree directly to checkout new Repo.
git setup

Share your findings with me and drop queries or troubles in comments, I will be happy to help! Happy coding!

Top Trends going to Impact iOS Application Development in 2019

The latest version of iOS 12.1.4 was released last week. Apple has fixed a security...

Enterprise Mobility Solutions- Top Tips to Get Benefits for Your Business in 2019

Enterprise mobility can be a game changer for companies. When it comes to growing your...

4 Features of a Mobile App That Everyone Needs

There is a multitude of options in every category for mobile applications on all the...

We are always happy to hear from you - Share your business requirements. Our business experts will reach you shortly


Select Your Requirement

Secure : We'll ensure, all the information provided by you will not be shared with anyone and your details are completely safe.

We respect your privacy. *Privacy Policy

Select Your Requirement

Secure : We'll ensure, all the information provided by you will not be shared with anyone and your details are completely safe.

We respect your privacy. *Privacy Policy