“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.
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.
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:
git clone --bare mypreciousss mypreciousss.git
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://firstname.lastname@example.org/~/src/mypreciousss.git mypreciousss
This should do it.
However there’s one catch: on Linux boxen git will ask for a password for email@example.com 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.