Skip to content

Instantly share code, notes, and snippets.

@madprops
Created August 9, 2022 01:27
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 madprops/34a35c09749c5218ef5cbbf1905f7756 to your computer and use it in GitHub Desktop.
Save madprops/34a35c09749c5218ef5cbbf1905f7756 to your computer and use it in GitHub Desktop.
Backup your public repos. Usernames/Orgs as arguments
import os
import sys
import requests
from pathlib import Path
def main():
usernames = sys.argv[1:]
for user in usernames:
userdir = Path(user)
if not userdir.exists():
userdir.mkdir()
res = requests.get(f"https://api.github.com/users/{user}/repos?per_page=100")
json = res.json()
names = [repo["name"] for repo in json]
for name in names:
repodir = Path(f"{user}/{name}")
if repodir.exists():
print(f"Pulling: {user} / {name}")
os.popen(f"git -C {user}/{name} pull").read()
else:
print(f"Cloning: {user} / {name}")
os.popen(f"git -C {user} clone https://github.com/{user}/{name}").read()
# Program starts here
if __name__ == "__main__": main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment