Skip to content

Instantly share code, notes, and snippets.

@jlongster
Created February 1, 2011 20:05
Show Gist options
  • Save jlongster/806555 to your computer and use it in GitHub Desktop.
Save jlongster/806555 to your computer and use it in GitHub Desktop.
#!/bin/sh
exec 2>&1
root="/sites/dev.mozilla.james.local"
master_dir="$root/master"
branch_dir="$root/branches"
if ! [ -d "$master_dir" ]; then
echo "master repo not available" && exit 1
fi
mkdir -p "$branch_dir"
cd "$master_dir"
git remote prune origin
git fetch
for ref in .git/refs/remotes/origin/*; do
branch=`basename "$ref"`
dest="$branch_dir/$branch"
if [ "$branch" == "HEAD" ]; then
continue
fi
if ! [ -f .git/refs/heads/"$branch" ]; then
git branch "$branch" origin/"$branch"
git clone "$master_dir" "$dest"
(cd "$dest" && git checkout "$branch")
else
(cd "$dest" && git pull > /dev/null)
fi
done
cd "$branch_dir"
for branch in *; do
if ! [ -f "$master_dir/.git/refs/remotes/origin/$branch" ]; then
rm -rf "$branch"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment