
This configuration helps make my consistent pulling of repositories from GitHub a bit easier. Especially so if repositories can frequently change names, or the list of all current repositories can change.
I wrote a script to clone all (specific) repositories in an organization.
Context
My setup is currently running macOS Catalina, using iTerm2 with Bash.
You will needhomebrew
,jq
, andgh
:
/bin/bash-c"$(curl-fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"brewinstalljqbrewinstallgh
Operation
For this configuration, ensure you're in the desired directory and this script exists in the directory. This will create a new directory (named the date, i.e.2020-12-06T21:16:47Z
) where you are, and then dump all the clones within that directory:
bash ./<SCRIPT_NAME>.sh INSERT_GITHUB_ORGANIZATION# bash ./replenishRepos.sh accordproject
Configuration
All
My configuration within thisscriptName.sh
file in order to cloneall repositories within an organization:
#!/bin/bashCURRENTDATE=$(date-u +"%Y-%m-%dT%H%M%SZ")repositories=(`gh api /orgs/$1/repos--paginate | jq-r'.[]' |tr'\n'' '`)mkdir"${CURRENTDATE}"cd"${CURRENTDATE}"echo"####"echo"## Cloning repositories"echo"####"forrepoin"${repositories[@]}"doecho"####"echo"# Cloning repo https://github.com/clauseHQ/${repo}.git"echo"####" git clone"https://github.com/clauseHQ/${repo}.git"done
Specific
My configuration within thisscriptName.sh
file in order to cloneonly repositories within an organization that have specific prefixes, are archived, and are private:
#!/bin/bashCURRENTDATE=$(date-u +"%Y-%m-%dT%H%M%SZ")repositories=(`gh api /orgs/$1/repos--paginate | jq-r'.[] | select(.private == <BOOLEAN> and .archived == <BOOLEAN>) | .name | select(test("<PREFIX_1>") or test("<PREFIX_2>"))' |tr'\n'' '`)mkdir"${CURRENTDATE}"cd"${CURRENTDATE}"echo"####"echo"## Cloning repositories into${CURRENTDATE}"echo"####"forrepoin"${repositories[@]}"doecho"####"echo"# Cloning repo https://github.com/clauseHQ/${repo}.git"echo"####" git clone"https://github.com/clauseHQ/${repo}.git"done
In this configuration, I can select archived or private repositories, and/or repositories with a specific prefix in the name.
Top comments(0)
For further actions, you may consider blocking this person and/orreporting abuse