Created
January 17, 2023 12:24
-
-
Save thamognya/ac4c9ca9d269f01ddf788f134221752e to your computer and use it in GitHub Desktop.
Convert git branches to folders
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
# https://stackoverflow.com/questions/63381853/any-way-to-turn-all-git-branches-into-folders-for-a-repository | |
#!/usr/bin/env bash | |
#### | |
# | |
# $1 = Remote URL to be clonned | |
# $2 = New name of the repository | |
# | |
#### | |
remote=$1 | |
repository=$2 | |
workdir=$(pwd) | |
destination="$workdir/$repository" | |
echo "Creating repository at $destination" | |
mkdir "$destination" | |
git clone "$remote" "$repository" | |
cd "$repository" | |
for branch in $(git ls-remote --heads origin | grep -o "refs/heads/.*$" | cut -d / -f 3-) | |
do | |
echo "Cloning into branch $branch" | |
git clone -b $branch --single-branch $remote "$destination/$branch" | |
done | |
echo "Current dir: $(pwd)" | |
echo "Deleting all .git and .gitignore files" | |
rm -rf "$destination"/*/.gitignore | |
rm -rf "$destination"/*/.git | |
rm -rf "$destination"/.gitignore | |
rm -rf "$destination"/.git | |
cd $workdir | |
echo "All done! cur dir: $(pwd)" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment