Skip to content

Instantly share code, notes, and snippets.

@xnzac
Last active December 25, 2015 16:09
Show Gist options
  • Save xnzac/7003545 to your computer and use it in GitHub Desktop.
Save xnzac/7003545 to your computer and use it in GitHub Desktop.
Fetch all forks of github repository. Uses gems 'github_api' and 'hub'
#!/usr/bin/env ruby
# Install gems:
# gem install github_api
# gem install hub
#
# Then run script in github repo
require 'github_api'
g = Github.new
path = `git remote show -n origin | grep Fetch | cut -d: -f2-`
raise "You're not in a git repo with an origin remote" if path.empty?
username, repo = path.split("/")[0].split(":")[1], path.split("/")[1].split(".")[0]
forks = g.repos.forks.list username, repo
usernames = forks.map(&:owner).map(&:login)
usernames.each do |username|
puts "hub fetch #{username}"
`hub fetch #{username}`
end
@dinglixiang
Copy link

Try to get correct path, username and repo.

path = git remote show -n origin | grep Fetch | cut -d: -f2-
username, repo = path.split("/")[0].split(":")[1], path.split("/")[1].split(".")[0]

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