Skip to content

Instantly share code, notes, and snippets.

@aereal
Created March 21, 2015 13:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aereal/236de21b57c11befc8a5 to your computer and use it in GitHub Desktop.
Save aereal/236de21b57c11befc8a5 to your computer and use it in GitHub Desktop.
#!/bin/bash
set -e
repository_name() {
basename "$(git rev-parse --show-toplevel)"
}
export_branch() {
branch_name="$1"
git archive \
--format=tar \
--prefix "$(repository_name)-${branch_name}/" \
${branch_name} \
| tar -C . -xf -
}
export_all_branch() {
branches=($(git for-each-ref --format='%(refname:short)' -- refs/heads))
for b in "${branches[@]}"; do
export_branch $b
done
}
while getopts a opt ; do
case "$opt" in
a)
export_all_branch $@
;;
*)
export_branch $@
;;
esac
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment