Skip to content

Instantly share code, notes, and snippets.

@ayosec
Created April 27, 2011 00:54
Show Gist options
  • Save ayosec/943519 to your computer and use it in GitHub Desktop.
Save ayosec/943519 to your computer and use it in GitHub Desktop.
Nasty way to add every fork of a GitHub repository
#!/usr/bin/env ruby
# Nasty way to add every fork of a GitHub repository
if ARGV.size != 2
puts "Use: #$0 owner repository"
exit 1
end
current_remotes = File.read(".git/config").scan(/\[remote "(.*?)"\]/).flatten
require 'json'
JSON.parse(`GET https://github.com/#{ARGV[0]}/#{ARGV[1]}/network/members.json`)["users"].each do |item|
owner = item["owner"]["login"]
if not current_remotes.include?(owner)
git_url = "git://github.com/#{owner}/#{ARGV[1]}.git"
puts "Adding #{owner}: #{git_url}"
system "git remote add #{owner} #{git_url}"
end
end
@ayosec
Copy link
Author

ayosec commented Apr 27, 2011

To fetch every remote:

$ git remote | xargs -l1 git fetch

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