I recently started renting a virtual private server. I have a few experiments in mind (experimenting with Hadoop is a big one), but there are also a few necessities, e.g. my Shiny Server for developing webapps in R.

Another big use is having a private git server. When I develop for companies, I obviously don’t want the code to be public, which is a requirement for the free GitHub accounts.

Setting up this server is easy. I followed the instructions from the wonderful Pro Git book, conveniently available for free online. This site walks you through the one-time setup of a git server. In this article, I collect the commands for setting up a new repository on an existing server, for future references.

Create a new repository

ssh on your server as the git user, and execute:

# On the server:
cd /srv/git
mkdir projectname.git
cd projectname.git
git init --bare
# Make sure you're the user git. Otherwise, add:
cd ..
chown -R git:git projectname.git

This sets up a new bare repository.

Then, on your local machine:

# on your local computer
cd projectname
git init
git add .
git commit -m 'initial commit'
git remote add origin git@gitserver:/srv/git/projectname.git
git push origin master

Adding other users

The following post explains how to add a collaborator to your own server: