Last active
March 9, 2024 01:39
-
-
Save akumria/3405534 to your computer and use it in GitHub Desktop.
A quick way to find all the forks of a particular github project. see: https://github.com/akumria/findforks for a version which works now
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import os | |
import urllib2 | |
import json | |
import subprocess | |
user=None | |
repo=None | |
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 | |
try: | |
github = subprocess.check_output(github_cmd).strip() | |
user, repo = github.split('/')[-2:] | |
user = user.lstrip('[email protected]:') | |
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: | |
try: | |
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.") | |
os.exit(-1) | |
github_url='https://api.github.com/repos/%s/%s/forks' | |
resp = urllib2.urlopen(github_url % (user, repo)) | |
if resp.code == 200: | |
content = resp.read() | |
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 | |
subprocess.call(remote_add_cmd.split(" ")) | |
fetch_all_cmd="git fetch --all" | |
print fetch_all_cmd | |
subprocess.call(fetch_all_cmd.split(" ")) |
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
Got the 404 like @johndpope but fixed it by changing:
user.lstrip('[email protected]:')
into
user.replace('[email protected]:', '')
@mdamien, the gist is fairly old. You might want to use the repository instead:
See: https://github.com/akumria/findforks or https://gitlab.com/akumria/findforks
this is working https://gist.github.com/JanX2/f7fd01bbd37a863cbd0c6c3db6c37ca2
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This API might not have been available when this gist was created:
https://developer.github.com/v3/repos/forks/