Setting up Git on Centos

In this tutorial, I am showing how to setup GIT on Centos with SSH .

Packages to be installed :

yum install git-core gitosis

Create user and group which will own the repositories :

useradd -d /path/to/repositories gituser

Generate or copy a ssh key for use with git :

su gituser

ssh-keygen -t rsa

Now initialize the gitosis :

gitosis-init < /path/to/ur/sshPrivateKey

Be safe by changing permissions on the post update :

sudo chmod 755 /path/to/repositories/gitosis-admin.git/hooks/post-update

Clone the gitosis-admin repo into your local machine :

git clone gituser@yourServer:gitosis-admin.git

Now you should have gitosis.conf and keydir/ in your gitosis-admin directory.

Creating New Repositories :

Now is the time to create a new Repository (eg. testrepo)

Open up the gitosis.conf and see the default configuration :

vi gitosis.conf

[gitosis] [group gitosis-admin] writable = gitosis-admin members = gitUser

Now to Create a new repo, we just authorize writing to the repo and push the changes . Add the following to the gitosis.conf file :

[group mydevel]
members = user1@hostname user2@hostname 
writable = repoName

Save the changes commit and push it to the server :

git commit -a -m "New users to the repo repoName"
git push

Now create the repository and initialize it :

mkdir repoName

cd repoName git init git remote add origin gitUser@serverName:repoName.git

Now create some files , save changes, add to repo. If you want to add existing files then you can use * to represent all files:

git add fileName

or

git add *

Now commit & push to the origin

git commit –a –m “Initializing new Repo”

git push origin master:refs/heads/master

Adding Users to the Repo :

In order to add users, first get their key file and put them in the key dir folder. Please note that all keys must have .pub extension and the username is anything before .pub

Example :

cd gitosis-admin
cp ~/newUser1.pub keydir/
cp ~/newUser2.pub keydir/
git add keydir/newUser1.pub keydir/newUser2.pub

Now add the members to the list and commit changes :

git commit -a -m "Created New users newUser1 and newUser2"
git push

Now they can clone and start working on the project :

git clone newUser1@gitServer:testRepo.git

Configure Public access to the repo :

git-daemon --base-path=/path/to/repo/to/grantaccess/ --export-all

Note : In windows, you can use tortoise Git, you can save the session in putty and use the session name in stead of hostname in the commit and clone operations.

In unix , you can use non standard port by creating ssh config file :

http://www.mylinuxguide.com/handling-multiple-ssh-keys-and-ports-for-multiple-machines/

  1. No comments yet.

  1. No trackbacks yet.


− four = 5