Skip to content

Instantly share code, notes, and snippets.

@jridgewell
Created September 11, 2017 19:18
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 jridgewell/a93ca90c53183a6a3ba9392635c77620 to your computer and use it in GitHub Desktop.
Save jridgewell/a93ca90c53183a6a3ba9392635c77620 to your computer and use it in GitHub Desktop.
Checkout a git pr
#!/usr/bin/env ruby
# Based on https://gist.github.com/gnarf/5406589
pr, branch = ARGV
remote = 'origin'
if pr.nil?
puts "USAGE: git pr [REMOTE/]PR [BRANCH]"
puts "\tgit pr 123"
puts "\tgit pr upstream/123"
puts "\tgit pr 123 branch"
puts "\tgit pr upstream/123 branch"
exit 1
end
if pr =~ /\//
remote, pr = pr.split('/')
end
if branch.nil?
branch = "pr/#{pr}"
end
exec("git fetch -fu #{remote} refs/pull/#{pr}/head:pr/#{pr} && git checkout -B #{branch} pr/#{pr}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment