Last active
August 12, 2019 19:30
-
-
Save ashafer01/78703be49b33b091bcc0d78e8bc596da to your computer and use it in GitHub Desktop.
Mirror all of your accessible repos locally from github enterprise
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 | |
## Create or update a local mirror of all of your accessible repos on a GitHub Enterprise server | |
## Operates within the working directory | |
## Sets up a host/org/repo directory structure similar to Go | |
## Requires command line utilities: curl, jq, git | |
## Token available at https://github.YOUR-ENTERPRISE.com/settings/tokens | |
## Appears to need: repo (Full control of private repositories) permission, and read:org (Read org and team membership) permission | |
# configs | |
host="github.YOUR-ENTERPRISE.com" | |
token="YOUR_API_TOKEN" | |
user="$USER" | |
api="https://$host/api/v3" | |
page=1 | |
while [[ $page -le 20 ]]; do | |
n=0 | |
curl -u "$user:$token" "$api/user/repos?page=$page&per_page=100" | jq -r '.[].full_name' | while read repo; do | |
repo_path="$host/$repo" | |
if [[ ! -e "$repo_path" ]]; then | |
mkdir -p "$repo_path" | |
git clone "git@$host:$repo" "$repo_path" | |
else | |
pushd "$repo_path" | |
git pull | |
popd | |
fi | |
((n++)) | |
done | |
if [[ $n -eq 0 ]]; then | |
break | |
fi | |
((page++)) | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment