How to setup git on self hosted server.

Feb 3rd, 2016

How to setup git on self hosted server.

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. (http://git.example.com).

Knowledge Base:

If cost is not an issue, there are multiple services like github.com(Pricing model is number of repository based) and bitbucket.com (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:

Pros:

  • 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!

Cons:

  • 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 “id_rsa.pub” 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 “id_rsa.pub” 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 “id_rsa.pub” 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/id_rsa.pub /home/git/Git-Adm.pub
$ sudo chown git:git /home/git/Git-Adm.pub

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 https://github.com/sitaramc/gitolite

#2: Create bin folder at /home/git

$ mkdir bin

#3: Install gitolite

$ cd gitolite/
$ ./install
$ cd ..
$ /home/git/gitolite/src/gitolite setup -pk Git-Adm.pub
$ 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 gitolite-suexec-wrapper.sh

Paste below script:

#!/bin/bash
#
# 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/gitolite-suexec-wrapper.sh
$ chmod 755 /var/www/bin

Step #10: Modify “UMASK”

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

Change UMASK,

From:
UMASK => 0077

To
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 jaym.pub zaidp.pub ~/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

Output:
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@192.168.1.40:gitolite-admin.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
HostName
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

Output:
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!

Comments are closed.

Let's Discuss Your Project

Get free consultation and let us know your project idea to turn
it into an amazing digital product.

Let’s talk

NEWS & BLOG

Related Blogs

12 Effective Mobile App Development Strategies for 2023

Mobile App Jul 11th, 2023

12 Effective Mobile App Development Strategies for 2023...

Read more
Logistics App Development – A Comprehensive Guide For 2024

Logistics Jun 8th, 2023

Logistics App Development – A Comprehensive Guide...

Read more
Exploring Types, Modules, and Development Stages of Fleet Management Software

Mobile App Jun 6th, 2023

Exploring Types, Modules, and Development Stages of Fle...

Read more

INQUIRY

Let's get in touch

UNITED STATES

31236 Meadowview Square,
Delmar, DE 19940, USA

Sales: +1 667 771 6758

UNITED KINGDOM

13 Layton Road, Hounslow,
London, TW3 1YJ

Sales: +44 7404 607567

INDIA

2nd Floor, Sun Avenue One, Bhudarpura, Ayojan Nagar, Nr. Shyamal Cross Road, Ahmedabad, Gujarat-380006

Sales: +91 635-261-6164

For Project Inquiries

biolah

depo 25 bonus 25 to 5x

depo 25 bonus 25

depo 25 bonus 25

mndrmndr.com

bonusdeposit.net

https://www.greentourstanzania.com/wp-includes/customize/

https://temp1.novotest.biz/id/

depo 25 bonus 25

https://sumberjo-blitar.desa.id/images

https://sumberjo-blitar.desa.id/data

depo 25 bonus 25 to 5x

depo 25 bonus 25

https://www.greentourstanzania.com/wp-includes/js/product/

https://smpabbs.sch.id/gacor/100/

https://smpabbs.sch.id/gacor/bonus/

deposit 25 bonus 25

depo 25 bonus 25

bonus new member 100

https://ppdb.smk-kosgoro.sch.id/data/depo 25 bonus 25https://jesus.nouvellevie.com/wp-includes/images/Getoko.iddepo 25 bonus 25https://bonus-baru.s3.ap-southeast-1.amazonaws.com/link-daftar-slot-gacor.htmlhttps://bonus-baru.s3.ap-southeast-1.amazonaws.com/scatter-pink-paling-gacor.htmlhttps://worldlisteningproject.org/wp-includes/depo25bonus25/bonus new member 100depo 25 bonus 25

slot bonus new member 100