Git: private repositories on shared hosting

“You are a developer, software engineer, web designer, text writer… You want your files accessible from all the places (like a source for your project or a template for a website) – and you want to be sure that it is always the most up to date version…

Sure you can drag those files along on a USB stick and copy it forth and back. You have those files even if there’s no Internet access. Important? Sure but…”

Remember this? I have written very similar article on using Bazaar-NG for private repositories on shared hosting. It is time to make the same with git – which is becoming very popular due to its robustness and support from Linus and kernel devs themselves.

With MinGW Git port (no need for Cygwin!) coming to the light – git now looks as a great alternative to both Subversion and Bazaar.

Update:  With latest release a preliminary support for git-svn has been brought!

Let’s get things started.

I have a shared hosting at site5. Bazaar-NG is excellent choice, however it is a little tad slow. While it is comparable at startup time on my Gentoo box it’s startup on Windows box at work can be counted in a few seconds for each command. Git just seems faster for every operation I run.

Repository creation

Let’s assume that you have your precious sources/documents/whatever in ~/src/mypreciousss. We need to create a git repository there and make an initial commit.

cd ~/src/mypreciousss
git init
git add *
git commit -m "Initial commit"

That’s it. You’ve got your repo (+workspace) up and running.

Moving repo to remote host

Now it’s time to move the repo to shared hosting. This may seem a little bit awkward but it’s a little bit easier this way.

As we don’t need our working copy on remote host let’s just clone the sole repo:

cd ~/src
git clone --bare mypreciousss mypreciousss.git
touch mypreciousss.git/git-daemon-export-ok

No you can just scp/ftp mypreciousss.git to any directory on remote host. I’ve set a ~/src/ directory on remote host so the address of repository will look like this:


Next thing is to prepare git on shared hosting. This is due to fact, that – contrary to Bazaar ftp access – git needs itself available when using ssh:// protocol to access repository (however the same applies for Bazaar’s bzr+ssh repository access; you need bzr command available for your shell).

Just grab it from git’s website, run usual configure+make+make install and make it available in the path (eg. by exporting modified PATH in ~/.bashrc).


It’s time to test our remote repo. Just to make it a little bit more challenging remove both local repos:

rm -Rf ~/src/mypreciousss
rm -Rf ~/src/mypreciousss.git

And clone remote repository to local workspace:

git clone ssh:// mypreciousss

This should do it.

However there’s one catch: on Linux boxen git will ask for a password for while on Windows not (MinGW version at least). This is a common problem. The solution is to have a public/private ssh key created and installed on shared hosting. It will also ease the pain of using authorized access since you either don’t have to remember password for you ssh key (passwordless keys) or use ssh-agent. Second solution is recommended.


3 responses to “Git: private repositories on shared hosting

  1. You can also create the repository remote (“GIT_DIR=myproject.git git init”) then push via ssh to that repository.
    Also you do not need to touch “git-daemon-export-ok”, that file is used by git-daemon to export the repository via git://. Since you acces it via ssh you don’t need it.
    You don’t need to clone the repository again, just edit the .git/config file and add origin reference there (see git-push documentation)

  2. Good to know. I just find cloning easier (in terms of error-proofness) and also being a test if repository works as expected. The GIT_DIR usage looks nice!

  3. Without using GIT_DIR you need to rename the .git folder created by “git init” to myapp.git (that’s what bare cloning does anyway).

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