I recently had to relinquish my trusty dev machine (my work laptop) since I got a new job, and as such am relegated to using my old mac laptop at home for development until I either find a new personal dev machine or get a new work laptop. For those who don’t know, I’m leaving the DC area and moving to Seattle to work for Amazon, so that’s pretty cool! Downside is that it’s Java and Java kind of sucks, but I can still do f#, haskell, and all the other fun stuff on the side.

Anyways, since I’m setting up my home dev environment I wanted to pull back all my github repos in one go. If I only had a few of them I would’ve just cloned them by hand, but I have almost 30 repos, which puts me in the realm of wanting to automate it.

As any good engineer does, I did a quick google and found that someone had written a ruby script to clone all of a users repos using the github API. However, the script is outdated and the github API has changed. It no longer uses YAML, but now JSON, and the URL’s are all different.

So, here is the updated script:

  
#!/usr/bin/env ruby

require "json"  
require "open-uri"

username = "devshorts"

url = "https://api.github.com/users/#{username}/repos"

JSON.parse(open(url).read).map{|repo|  
 repo\_url = repo["ssh\_url"]

puts "discovered repository: #{repo\_url} ... backing up ..."

system "git clone #{repo\_url}"  
}  

Unlike the original script, this will clone to the current directory you are in using the same name of each repo (so no renaming it during the clone).

There are a ton of other backup options, but this was fun and simple (and a good way to get me back into using vim)