Skip to content

Instantly share code, notes, and snippets.

@elecnix
Created November 28, 2008 02:59
Show Gist options
  • Save elecnix/29886 to your computer and use it in GitHub Desktop.
Save elecnix/29886 to your computer and use it in GitHub Desktop.
Keep two huge disks in sync with git
# Read carefully. This script is mostly useless.
# It demonstrates how git could help keep two huge disks in sync, one bigger than the other.
# Execute like this:
# bash -xf git-travel-test
set -e
echo "suppose we build a really really big repo"
mkdir repo1
cd repo1
git init
touch PERSISTENT
touch 2B_REMOVED
touch 2B_RENAMED
touch 2B_MODIFIED
git add .
git commit -m "First commit"
echo "we copy the working copy to an other disk because we cannot afford a drive big enough for a full repo"
cd ..
rsync --recursive --verbose --update --delete --exclude=.git repo1 repo2
cp repo1/.git/refs/heads/master repo2/.commit-id
echo "now suppose repo2 travels 1000 km"
cd repo2
touch ADDED_WHILE_DETACHED
rm 2B_REMOVED
mv 2B_RENAMED RENAMED
echo "meaningwhile in repo1..."
cd ../repo1
touch NEW_COOL
echo modification >> 2B_MODIFIED
git add .
git commit -m "Second commit"
echo "repo2 now wants to synchronize: start by pushing all changes"
git checkout -b repo2 `cat ../repo2/.commit-id`
cd ../
rsync --recursive --verbose --update --delete --exclude=.git --exclude=.commit-id repo2 repo1
cd repo1
git add -f .
git diff --cached
git commit -m "from repo2"
git checkout master
git merge repo2
echo "repo2 now wants the new stuff"
cd ..
rsync --recursive --verbose --update --delete --exclude=.git --exclude=.commit-id repo1 repo2
cat repo1/.git/refs/heads/master > repo2/.commit-id
echo "Rince and repeat."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment