Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
A quick way to find all the forks of a particular github project. see: for a version which works now
#!/usr/bin/env python
import os
import urllib2
import json
import subprocess
github_cmd="git config --get remote.github.url".split(" ")
origin_cmd="git config --get remote.origin.url".split(" ")
# we want to determine the user / repository name
# my convention is that my own projects use 'github' as the remote
# origin when I created it. And, obviously, a clone will use 'origin'.
# so try them each
github = subprocess.check_output(github_cmd).strip()
user, repo = github.split('/')[-2:]
user = user.lstrip('')
repo = repo.rstrip('.git')
except subprocess.CalledProcessError:
pass # ok, so no remote called 'github', let's try origin
if user is None and repo is None:
origin = subprocess.check_output(origin_cmd).strip()
user, repo = origin.split('/')[-2:]
repo = repo.rstrip('.git')
except subprocess.CalledProcessError:
print("Could not determine user or repo.")
resp = urllib2.urlopen(github_url % (user, repo))
if resp.code == 200:
content =
data = json.loads(content)
for remote in data:
remote_add_cmd="git remote add %s %s" % (remote['owner']['login'], remote['clone_url'])
print remote_add_cmd" "))
fetch_all_cmd="git fetch --all"
print fetch_all_cmd" "))
Copy link

johndpope commented Jan 6, 2013

when I clone this repo - it fails. couldn't work it out I'm afraid.

but this url definitely works

File "./", line 35, in
resp = urllib2.urlopen(github_url % (user, repo))
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/", line 126, in urlopen
return, data, timeout)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/", line 400, in open
response = meth(req, response)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/", line 513, in http_response
'http', request, response, code, msg, hdrs)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/", line 438, in error
return self._call_chain(_args)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/", line 372, in _call_chain
result = func(_args)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/", line 521, in http_error_default
raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error 404: Not Found

Copy link

kaidokert commented Feb 21, 2015

Github forks api returns this header, so the script does not get all results

Link:; rel="next",; rel="last"

Copy link

frost-nzcr4 commented May 15, 2015

I've added a module find_forks based on this gist with python 3 support and it gets all forks.

Copy link

mattcollier commented Dec 29, 2015

This API might not have been available when this gist was created:

curl -i

Copy link

joeytwiddle commented Nov 7, 2019

I made a little bash + nodejs script to add all the forks as remotes, so we can pull down all the forks at once.

It generates commands like this:

git remote add ... git://..........
git remote add ... git://..........
git fetch --all

After running the script, you can use something like this to get an overview of what changed on all the different forks:

git log --remotes --stat --oneline --graph

Copy link

mdamien commented May 1, 2020

Got the 404 like @johndpope but fixed it by changing:



user.replace('', '')

Copy link

akumria commented May 3, 2020

@mdamien, the gist is fairly old. You might want to use the repository instead:

See: or

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