Using Amazon S3 as your private git repository

Been trying to move my git repositories and apps from my old (and expensive) VPS into Amazon’s EC2 when I asked myself whether it is possible to push use Amazon S3 as a git repository.

Some searching later, I found out the answer. YES!

It is not only possible to push your repositories into your S3 bucket, but its also possible to do so even when your bucket is in a non-US region.

The only real thing that you’d need to install is JGit, a java implementation of the git client.

Here’s a quick and dirty guide from my experience:

  1. Download jgit.sh and put it in a path that bash is already reading from.
# when you download your jgit from the link above, its typically in 
# a format like -jgit.sh
# rename that just to jgit and put it in a path-readable directory

# you may need to sudo

davidc@davidc-myawesomebox:/usr/local/bin> ls
jgit

davidc@davidc-myawesomebox:/usr/local/bin> chmod +x jgit

  1. Prepare your AWS security credential keys and create a .jgit file in your ~/.jgit
davidc@davidc-VirtualBox:~> vim .jgit

# Add the following
accesskey: aws access key
secretkey: aws secret access key
  1. Chmod 600 your .jgit file
davidc@davidc-VirtualBox:~> chmod 600 .jgit
  1. Create an S3 bucket in your AWS Console

  2. You’re set!


# .jgit could be any file you designate as your
davidc@davidc-VirtualBox:/home/me/awesomecode> git remote add s3 amazon-s3://.jgit@/.git

# push away
davidc@davidc-VirtualBox:/home/me/awesomecode>  jgit push s3 master

Extra: While this is great for hosting personal code where you’re the only developer, this is not that useful for multi-developer environments.

Your S3 bucket is set to ACL: private by default so its only accessible by you. If you’d like to make it accessible to the public (to download), in your ~/.jgit add the following line after your secret key:

acl: public

The public can then clone your repository by

git clone http://.s3.amazonaws.com/.git

Caveats: You cannot push to a S3 repository via http. You’d still need to make use of jgit and the amazon-s3 protocol.

Hope this helps!