你能从GitHub上的命令行发出拉请求吗?

似乎你必须与github.com交互来发起一个拉请求。是这样吗?

325546 次浏览

更新: 中心命令现在是一个官方的github项目,也支持创建把请求

原始:

似乎在hub命令中添加一个特别有用的东西:http://github.com/defunkt/hub或github gem: http://github.com/defunkt/github-gem

我建议将问题提交给那些需要它的项目。github的人都很有反应。

请注意: Some of this answer is now outdated. (2022-01-27)
(例如使用gh Gem)
目前唯一能够做到这一点的工具是hubgh.


一个男人搜索…

man git | grep pull | grep request

给了

git request-pull <start> <url> [<end>]

但是,尽管它的名字,它不是你想要的。根据文件:

生成一个请求,要求上游项目将更改拉入 他们的树。打印到标准输出的请求以 分支描述,总结变更并指出变更的位置

@HolgerJust提到的github宝石,做你想要的:

sudo gem install gh
gh pull-request [user] [branch]

其他人提到了github的官方hub包:

sudo apt-get install hub

brew install hub

然后

hub pull-request [-focp] [-b <BASE>] [-h <HEAD>]
我以前用过这个工具-虽然看起来需要先打开一个问题,但如果你使用github问题跟踪,它非常有用,真的简化了工作流程。Git打开拉取,然后从你所在或选择的分支提交一个拉取请求。 https://github.com/jehiah/git-open-pull < / p >

编辑:看起来你可以在飞行中创建问题,所以这个工具是一个很好的解决方案。

使用Hub命令行包装器你可以将它链接到git,然后你可以做 git pull-request < / p >

从hub的手册页:

   git pull-request [-f] [TITLE|-i ISSUE|ISSUE-URL] [-b BASE] [-h HEAD]
Opens a pull request on GitHub for the project that the "origin" remote points to. The default head of the pull request is the current branch. Both base and head of the pull request can be explicitly given in one  of  the  following  formats:  "branch",  "owner:branch",
"owner/repo:branch". This command will abort operation if it detects that the current topic branch has local commits that are not yet pushed to its upstream branch on the remote. To skip this check, use -f.


If TITLE is omitted, a text editor will open in which title and body of the pull request can be entered in the same manner as git commit message.


If instead of normal TITLE an issue number is given with -i, the pull request will be attached to an existing GitHub issue. Alternatively, instead of title you can paste a full URL to an issue on GitHub.

最后我自己做了,我发现它的工作更好的其他解决方案,周围。

https://npmjs.org/package/pullr

Git现在附带了一个子命令'git request-pull' [-p] <start> <url> [<end>]

你可以看到文档在这里

你可能会发现这很有用,但是它与GitHub的功能并不完全相同

我最近创建了一个工具,它完全是你想要的:

https://github.com/jd/git-pull-request

它在一个单一的命令中自动完成一切,分叉回购,推动PR等。它还支持更新PR,如果你需要编辑/修复它!

我使用简单的别名来创建拉请求,

alias pr='open -n -a "Google Chrome" --args "https://github.com/user/repo/compare/pre-master...nawarkhede:$(git_current_branch)\?expand\=1"'

除了github/hub,也就是充当Git的代理,你现在(2020年2月)有< >强cli/cli < / >强:

参见“增强你的命令行体验:GitHub CLI现在处于测试版

创建一个拉请求

创建一个分支,多次提交以修复问题中描述的错误,并使用gh创建一个拉请求来共享您的贡献。

cli/cli pr creation——https://i1.wp.com/user-images.githubusercontent.com/10404068/74261506-35df4080-4cb0-11ea-9285-c41583009e6c.png?ssl=1

通过使用GitHub CLI来创建拉取请求,当你还没有一个分叉时,它也会自动创建一个分叉,它会推送你的分支并创建你的拉取请求,以合并你的更改。


2020年4月:"GitHub CLI现在支持自动填充拉请求和自定义配置"

GitHub CLI 0.7从我们的测试用户提供的反馈中发布了几个最受欢迎的增强功能 自上一个小版本0.6以来,有三个主要特性:

  • 配置gh以使用您首选的编辑器gh config set editor [editor]
  • 配置gh默认SSH使用gh config set git_protocol ssh Git默认协议为HTTPS
  • gh pr create --fill自动填充你提交的拉取请求的标题和正文。

所以:

gh pr create --fill

你可以安装github官方CLI来创建PR并执行其他类型的的事情

设置:

gh auth login

创建PR:

gh pr create

合并:

gh pr merge

< p >是的。你可以安装中心 CLI util。
在MACOS上:brew install hub

你需要有一次GitHub令牌登录。

< p > User -> Dev settings -> Personal tokens -> Generate
(参见:https://github.com/settings/tokens) < / p >
git checkout -b mybranch
hub pull-request -b master -h mybranch


#user:     your_user_name
#password: your_git_token