Get git on a Server of Your Own

This article remains a work-in-progress.  You can clearly see its aim, but it may not get you on target.

The trouble with searching the Web for instructions relating to git and using your own git server is that mostly you will find articles for working with someone else’s repository server (like GitHub or so many others).  You can find quite good instructions for interacting with a remote server from your local development machine, but there are so many such instructions out there that locating useful information about using your own server to host git gets buried pretty deep.

Let’s go over some of the most basic pieces, and if you know how to use git with someone else’s repository server then you will be in good enough shape to sort out your specific situation.

On your server you’ll want to create a bucket for holding any and all of your git repositories (I broke mine into projects plus an archive folder).  So your paths may look like this:


In the above example, the folder I’ve called git is just the bucket which holds the repositories, and should not be used itself as a repository.  (If you are only planning a single repository I would still recommend using this structure as a way of being ready for the future.)

Move into each directory in turn and perform these actions.  Here we will just pick project1 and run through the steps.

cd project1
git init
git add .
git commit -m “initial commit of new repo”

Now you have a good master to begin.

Note, if you have files already in your project1 folder, great.  If not, you can instead run git init –bare but I find the above to my preference.  You won’t need to use git add until there is at least one file you want git to know about.  Commits just let git know that anything it knows you have changed is to be regarded as canon.

Now here is the secret sauce.  If you are not using a proper server but rather just trying to run git between two different development machines, this is not your best route.  In fact trying to run git between two different development machines represents some interesting challenges.  I definitely prefer this server-style.  So on your server you must detach your current brach (master) so that other (remote) repositories will be able to push to it.

git checkout –detach

Now you can visit your development machine and run through the usual steps to interact with your server-side repository.  I do this via ssh.

cd /path/to/where/you/want/gits
git clone username@gitservername:/path/to/git/project1

Add some files and make some changes. Then move into the project directory to add, commit, and push.

cd project1
git add .
git commit -m “useful commit message so you remember what the fuck you did”
git push

As near as I can tell this is the best way to manage that for oneself.  If there are better practices than those I’m using here, I’d like to see the detailed explanations for making them work and why they are a best practice.  Let me know.

Otherwise, have a great time with your newly minted git server.


Leave a Reply

Your email address will not be published. Required fields are marked *