Skip to content

Instantly share code, notes, and snippets.

@cyfrost
Created March 30, 2019 12:02
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 cyfrost/1cdbea49d151d4e090fbb37da443187a to your computer and use it in GitHub Desktop.
Save cyfrost/1cdbea49d151d4e090fbb37da443187a to your computer and use it in GitHub Desktop.
A basic pygithub3 example that shows how to get all the public and PRIVATE repos of a github user
#!/usr/bin/env python3
# This python script allows you to get all public and private repos of a given user (either by their name or by their OAuth token)
#
# For me, the intended use of this example is to use it backup all my repos to my machine (just in case :p)
#
# Usage:
#
# First install dependency using command: pip3 install pygithub3 --user
#
# Now copy paste your github token at line 15 as an argument (you CAN also use it like this: ....Github("my_github_username", "my_github_password")
#
# run this script like this: python3 get-private-repos-from-github.py
#
# and the output should be, that it'll print all the clone urls for the repos a given user has.
#
# you can do a lot more stuff with this, just read the pygithub3 docs.
import pygithub3
def main():
gh = pygithub3.Github("<YOUR_GITHUB_API_OAUTH_ACCESS_TOKEN_HERE>")
repos_list = []
for repo in gh.get_user().get_repos():
repos_list.append(repo.clone_url)
print(repos_list)
if __name__ == '__main__':
main()
@cyfrost
Copy link
Author

cyfrost commented Mar 30, 2019

This script at it's most basic level just prints the clone_url of all repos (including organization and the user's private repos as well).

A lot more can be done but this example intends to stay basic. Maybe you want to just do a git clone url or something like that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment