Last active
August 19, 2021 09:54
-
-
Save artlantis/fea385464828554253c2d66b56bc64c6 to your computer and use it in GitHub Desktop.
Get all remote branchs then create an archive in local folder
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 | |
# Steps to clone all branchs from remote repository to local directory | |
# | |
# mkdir work-dir-name | |
# cd work-dir-name | |
# git clone --bare remote-repository-url repo-name && cd repo-name | |
# git config --bool core.bare false | |
# git reset --hard | |
# change the 'grep -E' filter with appropiate repository names that you want to download | |
# change the target directory name in tar command | |
# chmod +X get-all-remote-branchs.sh | |
# sh get-all-remote-branchs | |
git clone --bare https://remote-repository.url/repository-name repository-name && cd repository-name | |
git for-each-ref --format='%(refname)' refs/heads/ | grep -E '(master)|(CHALLENGE)|(LECTURES-.*)' | while read branchRef; do | |
branchName=${branchRef#refs/heads/} | |
git archive --format=tar --prefix="$branchName/" "$branchRef" | tar -Cd:/target-directory-name -x | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment