Git Publishing (rgit): Paranoia, Syndication, Transparency
$ rgit HelloWorld # public bare repo
$ rgit -p WalledGarden # private bare repo
I’ve found myself using Git for nearly everything from organising my mp3, photo, and video collections, snapshot backups, synchronising devices, managing my love life, and walking my dog (just kidding about the videos). It’s fast, reliable, out of the way, and so damn useful, I wanted to find a way to create and publish a repository nearly instantly.
As I see it, there are only three use cases, all of which have only one user (namely me) with write permission. Those who insist on three additional use cases, and don’t mind the stench of centralised version control, might consider granting write permissions to multiple users via WebDAV. Though I argue in my upcoming rant entitled, Tyranny of the proletariat: Beyond authoritarianism and democracy, that multiple writers is symptomatic of an inefficient development model. The useful cases are: paranoia, syndication, and transparency.
In all cases, we create a repository remotely and clone it locally. In the paranoid case, the remote location is accessible only with encrypted transmission via SSH. The syndicate is publicly readable via Git over HTTP. The transparent case is web accessible and is also (in theory) publicly readable via Git.
Surprisingly enough, I’ve published the recipe for your coding pleasure (rgit from my home repo). First, you’ll need to configure four variables. I source them from startup rc (.bash_profile), but you may find it more convenient to add them directly to the recipe:
export SSH_DOMAIN=user@domain.web
export WEB_DOMAIN=sub.domain.web
export PATH_TO_WEB='~/path/to/public/web'
export PATH_TO_PRIV='~/priv/git'
Then decide if you want a paranoid (bare, SSH only), syndicate (bare, Git readable over HTTP), or transparent remote repository (work tree, web browsable). The paranoid user must add the -p flag. A transparent repository is created with the -w flag. A syndicate repository, which is readable by anyone with Git, is the default.
$ rgit HelloWorld
Generating public Git bare repository accessible via:
http://sub.domain.web/HelloWorld.git
ssh://user@domain.web/~/path/to/public/web/HelloWorld.git
Password:
Initialized empty Git repository in ~/path/to/public/web/HelloWorld.git/
Initialized empty Git repository in /home/user/local/HelloWorld/.git/
Created initial commit 5edcd54: Init with empty gitignore
0 files changed, 0 insertions(+), 0 deletions(-)
create mode 100644 .gitignore
Pushing commit to remote repository via ssh
Password:
Counting objects: 3, done.
Writing objects: 100% (3/3), 228 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
To ssh://user@domain.web/~/path/to/public/web/HelloWorld.git
* [new branch] master -> master
Completed
There are a few things to note. First, any web directory can limit access with htaccess/htpasswd files as well as similar mechanisms within git. Second, you’ll probably want to figure out how to share your SSH key with the remote server, else you’ll be typing your password frequently. Third, both -wp flags are possible, though it doesn’t make a lot of sense to create a remote work tree to an otherwise inaccessible repository. Even if you intend to do work on the remote server, it is recommended (by those in the know) to work in a clone of a bare repository. Finally, the transparent case does not work as intended. While all repositories can be cloned over SSH and bare repositories over HTTP, I’ve run into some problems cloning a work repository over HTTP:
local$ git clone http://sub.domain.web/home home.http
Initialized empty Git repository in ~/home.http/.git/
warning: remote HEAD refers to nonexistent ref, unable to checkout.
The primary motivation for syndicating the recipe is to find a solution to the above problem. The fully transparent workaround is to syndicate a bare repository and clone a work tree, such as home.git and home/. Perhaps this is just the case of publishing a web site. Transparency might be better handled by something like Trac, Git Web, or Cgit. Thoughts? Patches?
Inspiration:
- Casper Fabricius
- Ben Lynn’s Git Magic