Skip to content

Instantly share code, notes, and snippets.

@schcriher
Created May 15, 2017 17:28
Show Gist options
  • Save schcriher/d085cfc4cf6fa34251958b5e38c11f78 to your computer and use it in GitHub Desktop.
Save schcriher/d085cfc4cf6fa34251958b5e38c11f78 to your computer and use it in GitHub Desktop.
Clone a complete repository of github (all branches)
#!/bin/bash
if [[ $# -eq 0 || $# -ge 3 ]];then
echo "git cloneall path/url [folder]"
exit 1
fi
if [ -n "$2" ];then
folder=$2
else
name=${1##*/}
folder=${name%%.git}
if [ -z "$folder" ];then
echo "Destination folder could not be determined in '$1'"
exit 1
fi
fi
git clone $1 $folder
if [ $? -ne 0 ];then
exit 1
fi
cd $folder
git branch --all | grep '^\s*remotes' | egrep -v '(:?HEAD|master)$' | while read b
do
git branch --track ${b##*/} $b
done
git fetch --all
git pull --all
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment