cybercyber

Adding all github-forks as remotes

If you want to add all forks of a repository on github to your local remotes, use the following script:

#!bash
#!/bin/bash -eu
url=https://api.github.com/repos/$1/forks

while [ -n "$url" ]; do
    echo $url
    data=$(curl -i $url)
    links=$(echo "$data" | awk '/^Link: /{ print $0; exit}')

    echo "$data" | awk 'foo==1{print $0;};/^ *\r?$/{foo=1}' | jq -r '.[] | .owner.login + " " + .name + " " + .git_url' | while read line; do
        set -- $line
        git remote add $1-$2 $3 || true
        git fetch $1-$2
    done

    url=$(echo "$links" | sed -ne 's/.*<\([^>]\+\)>; rel="next".*/\1/p')
done

If you want to check on all the on-going development of a project on github, you will either have to track down the forks yourself or comb through the pull-requests. This script allows you to just download everything and look at all branches with a git-visualizer of your choice (gitk, SourceTree, …).

Have fun forking!