Skip to content

Instantly share code, notes, and snippets.

Last active October 13, 2023 20:50
  • Star 5 You must be signed in to star a gist
  • Fork 3 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?
Add all forks of the current repo as remotes
#!/usr/bin/env bash
set -e
# See also: (same thing but in python)
origin_url="$(git remote show origin | grep 'Fetch URL:' | sed 's+.*: ++')"
full_repo_name="$(echo "$origin_url" | sed 's+.* ; s+\.git$++')"
#[ -e "forks.json" ] ||
curl -s "${forks_url}" -o forks.json
node -e "
var forks = JSON.parse(fs.readFileSync('forks.json', 'utf-8'));
forks.forEach(forkData => {
console.log('git remote add \"' + forkData.owner.login + '\" \"' + forkData.git_url + '\"');
console.log('git fetch --all');
" |
if [ "$1" = -do ]
then bash
echo "Pass -do to execute above commands"
Copy link

joeytwiddle commented Nov 7, 2019

You can run this script in your current repo (and add the argument -do) to fetch all the forks on Github.

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

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

Add --patch if you want to see the actual line-by-line changes. Use / to search then n and N to step through matches.

Copy link

Nice script. But you didn't trim the .git from the end of full_repo_name and you left a hardcoded url in the call to curl. The curl line, when fixed, only pulled out 30 fork entries but I'm trying to use it on a repository that has over 400.

Nice use of node and readFileSync and the do bash option.

Copy link

That GitHub URL passed to curl takes a page option.

Copy link

johndpope commented Oct 4, 2020

I get an error

TypeError: forks.forEach is not a function
    at [eval]:3:9
    at ContextifyScript.Script.runInThisContext (vm.js:50:33)
    at Object.runInThisContext (vm.js:139:38)
    at Object.<anonymous> ([eval]-wrapper:6:22)
    at Module._compile (module.js:653:30)
    at evalScript (bootstrap_node.js:479:27)
    at startup (bootstrap_node.js:180:9)
    at bootstrap_node.js:625:3

Pass -do to execute above commands

maybe I need a specific nvm / npm

this worked for me

I switched to node 13 - but problem persists.

Copy link

JanX2 commented May 12, 2021

That issue cropped up for me, because git output is localized. The translation doesn’t contain 'Fetch URL:'. The result was an empty "forks.json".

My solution was to replace the screen scraping with git config --get remote.origin.url. That worked.


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