Skip to content

Instantly share code, notes, and snippets.

@cvan
Created August 7, 2023 05:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cvan/dea237cd56ec8d3a2811df1a4218845c to your computer and use it in GitHub Desktop.
Save cvan/dea237cd56ec8d3a2811df1a4218845c to your computer and use it in GitHub Desktop.
GitHub Org Archiver — using gh cli: https://cli.github.com
#!/bin/bash
NL=$'\n';
output_dir="$HOME/ghq/github.com";
repo_limit=100000;
org_slug="$1";
echo "<\!doctype html><html><meta charset='utf-8'><title>$org_slug</title></head><body><code><pre>$(gh repo list $org_slug --limit $repo_limit)</pre></code></body></html>""$NL" > index.html
list=$(gh repo list $org_slug --json name --jq '.[].name')
for repo_slug in $(echo $list | cut -d$'\t' -f1); do
pushd $output_dir/$org_slug;
gh repo clone $org_slug/$repo_slug $repo_slug || (\
pushd $repo_slug; \
git fetch --all ; git pull; \
popd; \
)
# echo git clone https://github.com/$org_slug/$repo_slug.git $repo_slug
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment