Wednesday, 2 November 2016

​Configure your own git server - Linux

In this post, I would explain on how to configure your own git server where you could manage your own code or your configuration files.  
I shall consider two servers one with hostname 'gitserver' other as a 'gitclient'.

Environment: Linux Centos 6
git version: 1.7.1

First, you would require to install 'git' on both the machines. 

#yum install -y git

Ensure you have created a password less authentication between 'gitserver' and 'gitclient'. incase any help needed refer - 

Create a project directory for git on your 'gitserver'

[root@gitserver ~]# mkdir python.git
[root@gitserver ~]# cd python.git/
[root@gitserver python.git]# git init --bare
Initialized empty Git repository in /root/python.git/
[root@gitserver python.git]#

Login to the 'gitclient' to create a git empty repository.

[root@gitclient ~]# mkdir python
[root@gitclient ~]# cd python/
[root@gitclient python]# git init
Initialized empty Git repository in /root/python/.git/

[root@gitclient python]# cat >
print "Hi .. I am from gitclient who will be commited to gitserver"
[root@gitclient python]# 

[root@gitclient python]# git add .
[root@gitclient python]# git commit -m "First git commit - Hello" -a
[master (root-commit) 5308ec1] First git commit - Hello
 Committer: root <>
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly:

    git config --global "Your Name"
    git config --global

If the identity used for this commit is wrong, you can fix it with:

    git commit --amend --author='Your Name <>'

 1 files changed, 2 insertions(+), 0 deletions(-)
 create mode 100644
[root@gitclient python]#

[root@gitclient python]# git remote add origin ssh://
[root@gitclient python]# git push origin master
Counting objects: 3, done.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 295 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
 * [new branch]      master -> master
[root@gitclient python]#

you can check from gitserver log regarding the commits.

[root@gitserver python.git]# git log
commit 5308ec10f87eab1c5bb474a5f42de26818915f7b
Date:   Wed Nov 2 13:57:48 2016 +0530

    First git commit - Hello
[root@gitserver python.git]#

If there are anyone who wants to add their code to this repository, they just would need to clone the repository to their local machine.

#git clone ssh://

they could now edit files, write commit change messages and then can push to the server. 

You can also add your repository in, incase if you need any help refer 

Git cheat sheet

Thanks for re-sharing