Simple Central Git Repository
Posted on 20. Sep, 2009 by Ash Christopher in Software Development
I have a new project that I am starting, and instead of using the familiar subversion for source control, I figured this was a great time to check out Git. An added bonus is we are looking at switching over to it at work – two birds.

Users can push and pull from other users or from a central repository.
The first thing you need to do is install git on both your clients and server. I am using Ubuntu, so you will have to figure out the equivalent commands and package names.
(client)$ sudo apt-get install git git-core (server)$ sudo apt-get install git git-core
Now that we have git on our server and client, we can start creating the git repository we want under source control.
The first thing we will do is create a git project. This can either be an existing code base you are already working on, or you can start a project from scratch. For the purposes of this example, we will start a new project.
(client)$ mkdir project (client)$ cd project (client)$ git init
Git should reply with the message ‘Initialized empty Git repository in .git/‘. Make a note of the .git directory created in our project – we will need it shortly.
I ran into my first issue here – the version of git I am using doesn’t seem to like to clone empty repositories. In order to allow me to clone (as you will see further down the page), we must have an initial commit.
(client)$ touch README (client)$ git add README (client)$ git commit -m "Initial commit." README
We want this new project to be available on a central Git repository (centralized decentralized version control system – the irony is not lost on me). The easiest way is to just scp the .git directory to the server and place them in the directory you plan on containing your repositories. In my case, I created a git directory off of / on the server.
(server)$ sudo mkdir /git (client)$ git clone --bare project project.git (client)$ scp -r project.git user@server:/git/
Essentially, we are finished adding the repository to the central server. We can now access the git repo from all clients so long as those users have ssh access to the central server. By default, we can access the repo from the clients using the ssh interface.
(client)$ git pull user@server:/git/project.git master
And we can push changes to the repo in a similar fashion.
(client)$ git push user@server:/git/project.git master
This is about as simple a set up as you can have. The Git server is really quite dumb. The real magic happens on the client side (which is left for another post when I have done a bit more research).
By default, this git server is private. Only users that have shell access to the server have access to push and pull changes. Push access requires private access, but for projects which you want public access, you can set up a git-daemon to serve git clone requests from the public. Rather than run it as a persistent process, you can quite simply tie it into xinetd with this simple configuration (remember, I am using Ubuntu).
(server)$ touch /git/project.git/git-daemon-export-ok (server)$ sudo apt-get install xinetd (server)$ sudo vi /etc/xinetd.d/git
service git
{
disable = no
type = UNLISTED
port = 9418
socket_type = stream
wait = no
user = nobody
server = /usr/bin/git-daemon
server_args = --inetd --export-all --base-path=/git
}
(server)$ sudo /etc/init.d/xinetd restart
This now gives us a public git repository url we can distribute to others.
(client)$ git clone git://server/project.git
Just remember that you still need to push changes to the repo via ssh.
UPDATE
Talked to one of the guys in #git on irc.freenode.net and he informed me that the usual practice is to create the git repo on the central server first, then clone it to the client and push changes from the client.


Albert Peschar
03. Dec, 2009
You don’t need to install the
gitpackage, which is the package for the GNU Interactive Tools. You should only install thegit-corepackage.Victor
22. Jul, 2010
What if i do not have the file /usr/bin/git-daemon ?? in my Ubuntu 10.04