Skip to content

Instantly share code, notes, and snippets.

@starlocke
Last active October 30, 2017 19:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save starlocke/a617f32e5ca23f0a4c6a to your computer and use it in GitHub Desktop.
Save starlocke/a617f32e5ca23f0a4c6a to your computer and use it in GitHub Desktop.
Print out all "git remote add" commands for all the forks of a project.
// Execute this function upon a project's "/network/members" page.
// - You also need to "inject" jQuery onto that page, first.
// Ex: https://github.com/example/test/network/members (replace "example/test" - NO LONGER WORKS)
// Ex: https://github.com/google/git-appraise-web/network/members (another example)
function add_all_github_forks(){
var matches = window.location.href.match(/github.com[/]\w+[/]([^/]+)/); // [^/]+ used to be \w+, now also captures "-" in names
var project_name = '';
if(matches == null){
console.log("no match, quitting early");
return;
}
else {
project_name = matches[1];
}
console.log("project name: " + project_name);
$('#network a[href$="\/'+project_name+'"]:contains("'+project_name+'"):gt(1)').each(function(){
var href = $(this).attr('href');
var remote = "https://github.com" + href + ".git";
var expr = new RegExp('[/]([^/]*)[/]'+project_name)
var match = href.match(expr);
var fork = match[1];
console.log("git remote add " + fork + " " + remote)
});
}
add_all_github_forks();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment