问题
I went ahead and followed this guide to allow me to checkout branches by their PR number rather than the branch name.
However, I am wondering if the reverse is possible, allowing me to get the branch name given a PR number from the command line. Is it doable?
回答1:
The short answer is no: there's no mapping (offered by GitHub by a standard Git-oriented interface, at least) showing the target branch of a pull request. However, all hope is not lost! The GitHub Pull Request API can give you the status of an existing pull request: GET /repos/:owner/:repo/pulls/:number
returns a rather large JSON blob that has the required information.
Note that parsing this JSON blob requires additional tools.
回答2:
Turns out not through github directly, but can be done through the very powerful hub
CLI tool created by Github themselves.
https://github.com/github/hub
With a combination of hub and parsing tools, you can checkout PR number 6350 like this:
git checkout $(hub pr list -f "%I|%H|%n" | grep "6350.*" | cut -d "|" -f2)
来源:https://stackoverflow.com/questions/51623918/git-getting-a-branch-name-from-a-pr