Last active
November 11, 2018 23:50
-
-
Save davidoram/24b9c38938fca0d708601b4fa62b26b3 to your computer and use it in GitHub Desktop.
Clone all github repositories for en organisation (git clone or git fetch --all)
This file contains hidden or 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 | |
# | |
# Checkout all repos, or brings branches up to date for an Org | |
# | |
read -d '' helptxt <<- "HELP_MSG" | |
Checkout all repos for a github organisation \\n | |
\\n | |
Usage:\\n | |
\\n | |
git_get_all org branch... Clone all github repos into the current directory.\\n | |
If there is a directory already matching a repo then run 'git pull origin branch' for each (ignores errors)\\n | |
HELP_MSG | |
set -e | |
if [[ "$1" = "" ]]; then | |
echo "Error missing arg" | |
echo -e $helptxt | |
exit 1 | |
fi | |
org=$1 | |
shift | |
allBranches=( "$@" ) | |
if [[ ${#allBranches[@]} -eq 0 ]]; then | |
echo "Error missing branch arguments" | |
echo -e $helptxt | |
exit 1 | |
fi | |
# See https://github.com/davidoram/ght | |
ght repos -o "${org}" > all_repos.txt | |
while read org_repo; do | |
echo '--------------------------------------------' | |
echo "$org_repo" | |
if [[ $org_repo =~ (.*)/(.*) ]]; then | |
org=${BASH_REMATCH[1]} | |
repo=${BASH_REMATCH[2]} | |
if [[ -d "${repo}" ]]; then | |
echo "Directory exists" | |
pushd "${repo}" | |
set +e | |
# Get latest of each branch | |
for branch in ${allBranches[@]}; do | |
echo " - git pull origin ${branch}" | |
git pull origin ${branch} | |
done | |
set -e | |
popd | |
else | |
echo "New directory - git clone" | |
git clone [email protected]:${org_repo}.git | |
fi | |
fi | |
done <all_repos.txt | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment