Created
June 11, 2010 20:30
-
-
Save jasoncodes/434991 to your computer and use it in GitHub Desktop.
A quick script to clone all your public repos on GitHub
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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