Skip to content

Instantly share code, notes, and snippets.

@c10b10
Last active December 11, 2018 08:48
Show Gist options
  • Save c10b10/fab1646d02b4458f8e28 to your computer and use it in GitHub Desktop.
Save c10b10/fab1646d02b4458f8e28 to your computer and use it in GitHub Desktop.
Clones all the private github repos from a certain organization, including branches, submodules and wiki
#!/usr/bin/env ruby
require "json";
# Change github credentials and organization name
github = {:user => "johndoe", :pass => "password", :org => "twitter"}
repos = `curl --user "#{github[:user]}:#{github[:pass]}" https://api.github.com/orgs/#{github[:org]}/repos\?per_page\=200\&type\=private`
for repo in JSON.load(repos)
puts "\n+++ Starting with " + repo["name"]
%x[git clone #{repo["ssh_url"]}]
branches = %x[cd #{repo["name"]} && git branch -r]
branches = branches.split(/\n/).map{ |branch| branch.split(" ").pop.split("/").pop }.uniq
default = branches[0]
branches.each{|branch| puts %x[cd #{repo["name"]} && git checkout #{branch} && git submodule update --init --recursive]}
# Change to default branch and clone the wiki
puts %x[cd #{repo["name"]} && git checkout #{default} && git fetch --all && git pull --all && git clone #{repo["ssh_url"].gsub(".git", ".wiki.git")} wiki]
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment