Skip to content

Instantly share code, notes, and snippets.

@pensierinmusica
Last active August 29, 2015 13:56
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 pensierinmusica/9296645 to your computer and use it in GitHub Desktop.
Save pensierinmusica/9296645 to your computer and use it in GitHub Desktop.
Helper to clone all GitHub repos from a given user
#!/usr/bin/env ruby
### Helper to clone all GitHub repos from a given user (requires Ruby)
# Insert here the GitHub username that you want to clone repos from
username = ""
# Insert your GitHub API access token, if needed (e.g. to access private repos)
#(http://help.github.com/articles/creating-an-access-token-for-command-line-use)
access_token = ""
# Switch to "true" if the GitHub user is an organization
org_flag = false
# Nothing to edit below this line
require "json"
require "open-uri"
if org_flag
url = "https://api.github.com/orgs/#{username}/repos"
else
url = "https://api.github.com/users/#{username}/repos"
end
if access_token.length > 0
url += "?access_token=#{access_token}"
JSON.parse(open(url).read).map{|repo|
repo_url = repo["ssh_url"]
puts "discovered repository: #{repo_url} ... backing up ..."
system "git clone #{repo_url}"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment