Skip to content

Instantly share code, notes, and snippets.

Last active October 17, 2019 01:17
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do? a quick hack to list my github repos from the command line.

Blog 2019/2/1

<- previous | index | next -> list your github repos from the command-line

This script gives you a convenient way to access your list of repos. Useful for piping the output into grep, etc.

#!/usr/bin/env python
# a simple script to list your github repos.
# usage:
# ./
# list all repos in the form <org>/<repo>
# ./ <org>
# list all repos for an org in the form <repo>
# export LSREPOS_USERNAME and LSREPOS_PASSWORD to avoid prompts.
import getpass
import os
import sys
import github
sys.stderr.write("Error: github module not found.\n")
sys.stderr.write("Please 'sudo pip install PyGithub'.\n")
orgname_filter = None
if len(sys.argv) > 1:
orgname_filter = sys.argv[-1]
if "LSREPOS_USERNAME" in os.environ:
username = os.environ["LSREPOS_USERNAME"]
username = raw_input("github username: ")
if "LSREPOS_PASSWORD" in os.environ:
password = os.environ["LSREPOS_PASSWORD"]
password = getpass.getpass("github password: ")
g = github.Github(username, password)
user = g.get_user()
repos = list(user.get_repos())
for repo in repos:
fullname = repo.full_name
(orgname, reponame) = fullname.split('/')
if orgname_filter:
if orgname == orgname_filter:
print reponame
print fullname
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment