Last active
November 18, 2021 22:15
-
-
Save germanviscuso/a77abd8a2fc64de7f15de6e43dbd904b to your computer and use it in GitHub Desktop.
Mirror/Sync Github Organization Repos locally
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 | |
# Clone all org repos (via ssh) | |
curl -s https://api.github.com/orgs/<organization>/repos?per_page=200 | python -c $'import json, sys, os\nfor repo in json.load(sys.stdin): os.system("git clone " + repo["ssh_url"])' | |
# Later pull from each repo | |
back=`pwd`; for d in `find . -type d -name .git` ; do cd "$d/.."; git pull origin; cd $back ; done |
The python part wasn't working for me in my server environment, or using the ssh_url
instead of the clone_url
. I also needed a version of this script that would work with private repos from an organization my account has access to. Here is my modified version of this:
#!/bin/bash
# Clone all org repos (via https)
curl --silent -i -u "<github_username>:<personal_access_token>" "https://api.github.com/orgs/<organization>/repos?per_page=200" | grep -oP '(?<="clone_url": ").+?(?=")' | while read line; do
echo $line
# Replace `github.com` in the clone url with `[email protected]`
git clone ${line/github/"<personal_access_token>@github"}
done
# Later pull from each repo
back=$(pwd)
for d in $(find . -type d -name .git); do
cd "$d/.."
git pull origin
cd $back
done
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Modifying it to
os.system("git clone --bare "
will mirror the bare repos, which can be nice if you want to be able to clone from the destination.