Last active
August 29, 2015 13:56
-
-
Save pensierinmusica/9296645 to your computer and use it in GitHub Desktop.
Helper to clone all GitHub repos from a given user
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 | |
### 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