您可以从 GitHub 上的命令行发出拉取请求吗?

问题描述 投票:0回答:12

似乎您必须与 github.com 交互才能发起拉取请求。是这样吗?

git github pull-request github-cli
12个回答
144
投票

更新hub命令现已成为官方github项目,并且还支持创建拉取请求

原版

似乎添加到 hub 命令中特别有用:http://github.com/defunkt/hub 或 github gem:http://github.com/defunkt/github-gem

我建议向那些有要求的项目提出问题。 github 上的人反应非常灵敏。


65
投票

Git 现在附带一个子命令

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

您可以在此处

查看文档

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


30
投票

使用 Hub 命令行包装器,您可以将其链接到 git,然后您可以执行以下操作

git pull-request

来自 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.

25
投票

一个男人搜索就像......

man git | grep pull | grep request

给予

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

但是,尽管有这个名字,但这并不是您想要的。根据文档:

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

@HolgerJust 提到 github cli 可以实现你想要的功能:

gh pull-request [user] [branch]

其他人提到了github的官方

hub
包:

sudo apt-get install hub

brew install hub 

然后

hub pull-request [-focp] [-b <BASE>] [-h <HEAD>]

18
投票

除了

github/hub
(它 充当 Git 的代理)之外,您现在(2020 年 2 月)还拥有
cli/cli

请参阅“增强您的命令行体验:GitHub CLI 现已处于测试阶段

创建拉取请求

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

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


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

GitHub CLI 0.7 已推出,根据我们的测试版用户提供的反馈,其中包含了一些最受强烈要求的增强功能。
自上一个次要版本 0.6 以来,有以下三个主要功能:

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

所以:

gh pr create --fill

7
投票

我最终制作了自己的,我发现它比周围的其他解决方案效果更好。

https://npmjs.org/package/pullr


7
投票

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

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

6
投票

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

设置:

gh auth login

创建公关:

gh pr create

合并:

gh pr merge


5
投票

我最近创建了一个工具,它完全可以满足您的需求:

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

它可以在单个命令中自动执行所有操作,分叉存储库,推送 PR 等。如果您需要编辑/修复它,它还支持更新 PR!


1
投票

我以前用过这个工具——虽然看起来需要先打开一个问题,但如果你使用 github 问题跟踪,它非常有用,并且确实简化了工作流程。 git open-pull 然后从您所在或选择的任何分支提交拉取请求。 https://github.com/jehiah/git-open-pull

编辑:看起来您可以即时创建问题,所以这个工具是一个很好的解决方案。


0
投票

是的。您可以安装 hub CLI 实用程序。
在 MACOS 上:

brew install hub

您需要拥有一次性 GitHub 令牌才能登录。

User -> Dev settings -> Personal tokens -> Generate

(参见:https://github.com/settings/tokens

git checkout -b mybranch
hub pull-request -b master -h mybranch

#user:     your_user_name
#password: your_git_token

0
投票

为什么不从 CLI 为我的拉取请求打开浏览器窗口?

假设您的 CLI 可以使用

open
命令打开浏览器窗口,您可以将此 git 别名添加到您的
~/.gitconfig
,它将为您的拉取请求打开一个新的浏览器窗口:

[alias]
    pull-request = "!f() { \
        REPO_NAME=$(basename -s .git `git config --get remote.origin.url`); \
        BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD); \
        URL=\"https://github.com/YOUR_ORGANIZATION/$REPO_NAME/compare/$BRANCH_NAME?expand=1\"; \
        open \"$URL\"; \
    }; f"

只需将

YOUR_ORGANIZATION
替换为您的组织名称即可。

然后设置完毕后,使用:

git pull-request

© www.soinside.com 2019 - 2024. All rights reserved.