Skip to content

Instantly share code, notes, and snippets.

@Stankye
Last active March 31, 2025 05:54
Show Gist options
  • Save Stankye/b214463a72e01b64a92052cc3fd3c72a to your computer and use it in GitHub Desktop.
Save Stankye/b214463a72e01b64a92052cc3fd3c72a to your computer and use it in GitHub Desktop.
Makes a list of a Github users stars or public repositories as clonable git url's

GitHoard

Makes a list of a Github users stars or public repositories as clonable git url's

Usage:

Requires "PyGithub"

pip install PyGithub

python githoard.py -u githubUser -m method -t githubToken -o output

  • -m takes either stars or repos, defaults to repos
  • Github tokens can be personal tokens
  • Github token (-t) can be passed in as a ENV GITHUB_TOKEN
  • Output (-o) is optional, will print to stdout if omitted

Examples:

python githoard.py -u stankye -m stars -t githubToken -o ./stars.txt

python githoard.py -u stankye -m repos -t githubToken

python githoard.py -u stankye -m stars

python githoard.py -u stankye

Why?

I personally use this to backup Github repos in bulk as well as track what repos are removed overtime

This is a slightly cleaner (ever so slightly) version of a quick script I made a few years back (https://gist.github.com/Stankye/ddc2d90627465134ef515af770f007ea)

#!/usr/bin/env python3
# Usage:
# python githoard.py -u <githubUser> -m <method> -t <githubToken> -o <output>
#
# Example:
# python githoard.py -u stankye -m stars -t <githubToken> -o ./stars.txt
#
import argparse
import os
from github import Github # pip install PyGithub
def main(githubUser: str, file: str, method: str, githubToken: str):
gh = Github(githubToken)
user = gh.get_user(githubUser)
if method == "stars":
results = user.get_starred()
elif method == "repos":
results = user.get_repos()
else:
print("Invalid method")
return
if file:
with open(file, "w", encoding="UTF-8") as f:
for r in results:
f.write(r.clone_url + "\n")
else:
for r in results:
print(r.clone_url)
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Github Hoarder")
parser.add_argument(
"-u", "--user", help="Github User to hoard from", type=str, required=True
)
parser.add_argument(
"-o",
"--output",
help="Output file",
type=str,
required=False,
)
parser.add_argument(
"-m",
"--method",
help="Operation to perform (stars | repos)",
default="repos",
type=str,
)
if "GITHUB_TOKEN" in os.environ:
parser.add_argument(
"-t",
"--token",
help="Github API Token",
type=str,
default=os.environ.get("GITHUB_TOKEN"),
)
else:
parser.add_argument("-t", "--token", help="Github API Token", type=str)
args = parser.parse_args()
main(args.user, args.output, args.method, args.token)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment