Skip to content

Instantly share code, notes, and snippets.

@artlantis
Forked from doulmi/download_all_branches.sh
Last active January 10, 2020 06:50
Show Gist options
  • Save artlantis/b6997febd74955a7ab3b815ab56dd623 to your computer and use it in GitHub Desktop.
Save artlantis/b6997febd74955a7ab3b815ab56dd623 to your computer and use it in GitHub Desktop.
Download All branches
#!/bin/bash
# Steps to clone all branchs from remote repository to local directory
#
# mkdir repo-name
# cd repo-name
# git clone --bare remote-repository-url .git
# git config --unset core.bare
# git reset --hard
# git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"
# git remote update
# chmod +X download_all_branches.sh
# sh download_all_branches.sh
set -x #echo on
remote_url=$(git config --get remote.origin.url)
for branch in $(git branch --all | grep '^\s*remotes' | egrep --invert-match '(:?HEAD|master)$'); do
branch_name=$(echo $branch| cut -d'/' -f 3)
git clone -b $branch_name $remote_url $branch_name
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment