Created
September 11, 2017 19:18
-
-
Save jridgewell/a93ca90c53183a6a3ba9392635c77620 to your computer and use it in GitHub Desktop.
Checkout a git pr
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 | |
# 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