Skip to content

Instantly share code, notes, and snippets.

@pavanpodila
Last active April 20, 2024 11:41
Show Gist options
  • Save pavanpodila/5273693 to your computer and use it in GitHub Desktop.
Save pavanpodila/5273693 to your computer and use it in GitHub Desktop.
Export each Git branch as a separate folder
previous_pwd=$PWD
cd $(dirname $0)
PROJECT="$HOME/Desktop/project"
EXPORT_DIR="$HOME/Desktop/export"
rm -rf $EXPORT_DIR
mkdir -p $EXPORT_DIR
rm -rf tmp
mkdir tmp
cd tmp
git clone $PROJECT .
branches=($(git branch -a | grep remotes | grep -v HEAD | grep -v master))
for branch in $branches; do
local name=${branch/remotes\/origin\//}
git checkout origin/$name
cp -R ./ $EXPORT_DIR/$name
done
cd ..
rm -rf tmp
# back to where we were
cd $previous_pwd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment