Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Add all forks of the current repo as remotes
#!/usr/bin/env bash
set -e
# See also: https://github.com/frost-nzcr4/find_forks (same thing but in python)
origin_url="$(git remote show origin | grep 'Fetch URL:' | sed 's+.*: ++')"
full_repo_name="$(echo "$origin_url" | sed 's+.*github.com/++ ; s+\.git$++')"
forks_url="https://api.github.com/repos/${full_repo_name}/forks"
#[ -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
else
cat
echo
echo "Pass -do to execute above commands"
fi
@joeytwiddle

This comment has been minimized.

Copy link
Owner Author

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.

@FrankReh

This comment has been minimized.

Copy link

FrankReh commented Jan 12, 2020

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.

@FrankReh

This comment has been minimized.

Copy link

FrankReh commented Jan 12, 2020

That GitHub URL passed to curl takes a page option.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.