Skip to content

Instantly share code, notes, and snippets.

@ryanfb
Created October 31, 2013 19:53
Show Gist options
  • Save ryanfb/7255975 to your computer and use it in GitHub Desktop.
Save ryanfb/7255975 to your computer and use it in GitHub Desktop.
Clone all forks in a GitHub repository's network.
#!/usr/bin/env ruby
require 'json'
require 'open-uri'
require 'fileutils'
def clone_repo(repo)
puts repo['full_name']
owner, path = repo['full_name'].split('/')
FileUtils.mkdir_p(owner)
unless File.directory?(repo['full_name'])
`git clone "#{repo['clone_url']}" "#{repo['full_name']}"`
end
end
github_api = "https://api.github.com/repos"
master = File.join(ARGV[0],ARGV[1])
FileUtils.mkdir_p(master)
Dir.chdir(master)
clone_repo(JSON.parse(open("#{github_api}/#{ARGV[0]}/#{ARGV[1]}").read))
forks = JSON.parse(open("#{github_api}/#{ARGV[0]}/#{ARGV[1]}/forks").read)
forks.each do |fork|
clone_repo(fork)
end
@endolith
Copy link

This probably doesn't work for cloning all forks of a gist, does it?

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