Git: Getting a Branch Name from a PR

瘦欲@ 提交于 2021-01-28 09:11:09

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!