Skip to content

Instantly share code, notes, and snippets.

@artlantis
Last active August 19, 2021 09:54
Show Gist options
  • Select an option

  • Save artlantis/fea385464828554253c2d66b56bc64c6 to your computer and use it in GitHub Desktop.

Select an option

Save artlantis/fea385464828554253c2d66b56bc64c6 to your computer and use it in GitHub Desktop.

Revisions

  1. artlantis renamed this gist Aug 19, 2021. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. artlantis created this gist Aug 19, 2021.
    18 changes: 18 additions & 0 deletions get-all-remote-branchs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    #!/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