Skip to content

Instantly share code, notes, and snippets.

@Demonstrandum
Last active October 3, 2017 19:11
Show Gist options
  • Save Demonstrandum/9e7a7bd474648089bad0aff721253171 to your computer and use it in GitHub Desktop.
Save Demonstrandum/9e7a7bd474648089bad0aff721253171 to your computer and use it in GitHub Desktop.
Clone all GitHub Repos
#!/usr/bin/env ruby
require 'net/http'
require 'uri'
require 'json'
raise ArgumentError, 'Expected at least 1 CLI argument!' if ARGV.empty?
root = user = String.new
%w{ git Git GitHub github repos }.each do |folder|
home = "#{File.expand_path '~'}/#{folder}"
if File.directory? home
root = home
break
end
end
ARGV.each { |arg| root = arg if File.directory? arg }
user = (ARGV - [root]).first
uri = URI.parse "https://api.github.com/users/#{user}/repos?per_page=999"
response = Net::HTTP.get_response uri
json = JSON.parse response.body
json.each do |repo|
puts %x{ git clone #{repo['ssh_url']} #{"#{root}/#{repo['name']}"} 2>&1 }
puts "Done!\n "
end
@Demonstrandum
Copy link
Author

Demonstrandum commented Sep 29, 2017

Installation, copy this to your terminal:

BACK="$(pwd)"; git clone https://gist.github.com/9e7a7bd474648089bad0aff721253171.git && cd 9e7a7* && chmod +x *.rb && sudo mv *.rb /usr/bin/clone-all; cd "$BACK"; rm -rf 9e7a7*

Then you can run

clone-all MyGithubUsername ~/MyFolderToBeFullOfGitRepos

from anywhere.

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