Skip to content

Instantly share code, notes, and snippets.

@jasoncodes
Created June 11, 2010 20:30
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 jasoncodes/434991 to your computer and use it in GitHub Desktop.
Save jasoncodes/434991 to your computer and use it in GitHub Desktop.
A quick script to clone all your public repos on GitHub
#!/usr/bin/env ruby
require 'net/http'
require 'yaml'
username = `git config github.user`.strip
if username.empty?
$stderr.puts "Please set github.user in your git config: https://github.com/account"
exit 1
end
uri = URI.parse("http://github.com/api/v2/yaml/repos/show/#{username}")
repos = YAML::load(Net::HTTP.get(uri))
errors = []
repos['repositories'].each do |repo|
puts "Cloning #{repo[:owner]}/#{repo[:name]}..."
unless system "git clone #{repo[:url]}.git"
errors << repo[:name]
end
end
puts
if errors.empty?
puts "Done."
else
$stderr.puts "The following repos failed to clone: #{errors.join ', '}"
exit 1
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment