Created
March 21, 2015 13:32
-
-
Save aereal/236de21b57c11befc8a5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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