Git-ipfs - A helper script to push git repositories to IPFS

Inspired by the “git” example in the docs, I’ve built this:

#!/bin/sh

set -e

TMP="$(mktemp -d)"
git clone -q --bare . "$TMP"
cd "$TMP"
git update-server-info
if [ objects/pack/*.pack != 'objects/pack/*.pack' ]; then
	cat objects/pack/*.pack | git unpack-objects
	rm -f objects/pack/*
fi
HASH="$(ipfs add -Qr .)"
rm -rf "$TMP"

if [ -n "$1" ]; then
	ipfs name publish --key=$1 "/ipfs/$HASH"
else
	echo "$HASH"
fi

Usage: from inside any git working directory, type git ipfs to “push” the whole repository to IPFS. Type git ipfs <key-name> to push to IPFS and then assign the result to the given IPNS key

5 Likes