How to make a Git server: The quick and dirty way

How to make a Git server: The quick and dirty way

Just as I was organizing my thoughts for the second part of my Getting started with Git series, I realized that it will all pretty much revolve around working with remotes – so here’s a quick guide to install and configure a git server. While this method is not the recommended way of doing things, it will get them done quite fast but don’t expect any sophisticated security or easy repository management.

This guide will get you up and running your Git server in no time, so that you can get right into creating new repositories that you and anyone else who has access to the server can clone locally, pull from and push to.

Step 1

SSH into your server and install git:

sudo apt-get install git

Step 2

Create a directory to hold your repositories and make sure it has the right user permissions:

sudo mkdir /srv/git

Step 3

Create and initialize your first repository by making a new directory and initializing a new bare git repository there:

mkdir /srv/git/my-repository.git
cd /srv/git/my-repository.git
git init --bare

Step 4

Clone your repository locally and make your first commit and push:

cd /var/www/public_html
git clone ssh://you@server-address/srv/git/my-repository.git
cd my-repository

At this point, it’s time to add some files to this empty directory, or start making them one by one if you feel that hardcore. If you run a git status command, you’ll see that your file(s) are all there but not currently being tracked, so we should add them to the staging area:

git status
git add .

Time to make our first commit and add a meaningful message to it, like “Initial commit”. But no, really, these sort of messages are only permitted on first commits, for all the rest of them you should try to be as descriptive as possible and always to the point… oh hell, I’ll just write a separate post for that later on.

git commit -m "Initial commit"

We can now safely push this commit to the remote repository and also set our master branch to track the remote master branch for changes by using the -u option just this one time only. If you haven’t done this already, it’s about damn time you set up passwordless SSH login, it can and most probably will save lives.

git push -u

Updating your local copy with the potential changes from the remote before pushing your own is usually considered good practice, especially if you’re not the only one working on the repository. A little git pull every now and then never hurt anyone – well, except for the times you get conflicts.

That’s when sh*t gets ugly and even though the rational thing is to just calm down work them out one by one, it really pays off to storm out of your cubicle, bloodshot eyes, swinging a DIY nunchuck made of keyboards / mice / extension cords / what have you, spitting death threats at your co-workers…

This will get you a reputation and / or a night in jail so be ready for both. For more tips on moronic behavior, follow my guide on How To: Make A Rep In Jail In The First 12 Hours. Just kidding… am I?… kidding… or am I?…


3 thoughts on “How to make a Git server: The quick and dirty way

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s