Skip to content

Instantly share code, notes, and snippets.

@artlantis
Last active August 19, 2021 09:54
Show Gist options
  • Save artlantis/fea385464828554253c2d66b56bc64c6 to your computer and use it in GitHub Desktop.
Save artlantis/fea385464828554253c2d66b56bc64c6 to your computer and use it in GitHub Desktop.
Get all remote branchs then create an archive in local folder
#!/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