【问题标题】:Can you issue pull requests from the command line on GitHub?你可以从 GitHub 上的命令行发出拉取请求吗?
【发布时间】:2011-05-01 13:50:41
【问题描述】:

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

【问题讨论】:

标签: git github pull-request github-cli


【解决方案1】:

没有。您必须安装 hub CLI 实用程序。 MACOS:冲泡安装集线器

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

用户 -> 开发设置 -> 个人令牌 -> 生成 https://github.com/settings/tokens

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

用户:你的用户

密码:git token

【讨论】:

    【解决方案2】:

    您可以安装 github official CLI 来创建 PR 并执行其他类型的 things

    设置:

    gh auth login

    创建公关:

    gh pr create

    合并:

    gh pr merge

    【讨论】:

      【解决方案3】:

      我个人喜欢在打开 PR 之前查看 GitHub 中的差异。另外,我更喜欢在 GitHub 上写 PR 描述。

      出于这些原因,我创建了一个别名(或者从技术上讲是一个没有参数的函数),它打开了 GitHub 中当前分支和主分支之间的差异。如果您将其添加到您的 .zshrc.bashrc,您将能够简单地输入 open-pr 并在 GitHub 中查看您的更改。仅供参考,您需要推送您的更改。

      function open-pr() {
        # Get the root of the github project, based on where you are configured to push to.  Ex: https://github.com/tensorflow/tensorflow
        base_uri=$(git remote -v | grep push | tr '\t' ' ' | cut -d ' ' -f 2 | rev | cut -d '.' -f 2- | rev)
      
        # Get your current branch name
        branch=$(git branch --show-current)
      
        # Create PR url and open in the default web browser
        url="${base_uri}/compare/${branch}/?expand=1"
        open $url
      }
      

      【讨论】:

        【解决方案4】:

        除了github/hub,其中acts as a proxy to Git,您现在(2020 年 2 月)还有cli/cli

        见“Supercharge your command line experience: GitHub CLI is now in beta

        创建拉取请求

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

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


        2020 年 4 月:“GitHub CLI now supports autofilling pull requests and custom configuration

        GitHub CLI 0.7 已经发布,根据我们的 Beta 版用户提供的反馈,我们提供了几项要求最高的增强功能。
        自上一个次要版本 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
        

        【讨论】:

          【解决方案5】:

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

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

          【讨论】:

          • 这不是创建PR,而是打开带有PR创建页面的浏览器。
          【解决方案6】:

          一个男人搜索...

          man git | grep pull | grep request
          

          给予

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

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

          生成一个请求,要求您的上游项目将更改拉入 他们的树。打印到标准输出的请求以 分支描述,总结变化并指出它们从哪里开始 可以拉。

          @HolgerJust 提到了 github gem 可以满足您的需求:

          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 发出的拉取请求无关
          • @Flov 通过“This”,我假设您的意思是 git request-pull 行。是的,这是有道理的,但我很惊讶 git 没有像 github 那样通过电子邮件发送拉取请求的命令。毕竟,git config user.email 可供它使用。尤其是使用名为 pull-request 的命令。
          • 对于 Ubuntu,看起来 github-cli 在 Precise 之后不再可用...我已经 opened a question 寻求替代方案。
          • bitbucket 或 gitlab 呢?来自 CLI 的任何命令?
          • @GamerAtmos 虽然这不是一个拉取请求,但它已经接近了。在 GitLab 上,您可以使用普通的 git 客户端创建一个新的私有存储库(项目),只需一个 git push -u origin master 和一个新的 origin url。
          【解决方案7】:

          更新hub命令现在是官方github项目,也支持创建pull requests

          原创

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

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

          【讨论】:

          • github-gem 包含一个为年龄创建拉取请求的工具:gh pull-request [user] [branch]
          • 在没有 Github 分叉 repo 的情况下是否可以工作,即从源 repo 的直接克隆?
          • @Holger Just 和其他任何人:这只是创建拉取请求的文本,不会绕过对 Github 分叉的需求。我还没有找到解决方法。我打算尽快尝试下面发布的“pullr”实用程序。请参阅here,了解人们从 github-gem 请求完全拉取请求支持的问题。
          • 使用hub进行快速命令:hub pull-request -m "message pull request" -b master -h your_branch
          • 不知道为什么上面的文档中没有提到它,但是为了快速合并请求,检查你的主分支做hub merge https://github.com/repo/pull/1
          【解决方案8】:

          Git 现在附带一个子命令 'git request-pull' [-p] &lt;start&gt; &lt;url&gt; [&lt;end&gt;]

          您可以查看文档here

          您可能会发现这很有用,但it is not exactly the same as GitHub's feature

          【讨论】:

          • @NathanBasanese 它生成描述拉取请求的人类可读文本。 git docsGitHub 书说要将其通过电子邮件发送给项目维护者,即对共享存储库(可能是 github)具有写入权限的人。维护者审查您发送的拉取请求文本(而不是使用 github 的在线拉取请求流程)。他们可以对您的拉取请求中指示的 url 和分支执行 git pull,以将您的更改合并到他们的本地克隆中并将这些更改推送到 github。
          【解决方案9】:

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

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

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

          【讨论】:

            【解决方案10】:

            使用Hub command-line wrapper,您可以将其链接到 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.
            

            【讨论】:

            • 不知道 Hub,可以通过自制软件获得:brew install hub 这似乎是 mac 用户的正确答案。
            • // , 有没有在线的地方可以让人们了解有关 Hub 的更多信息?
            • 更多关于 hub 命令的信息在这里:hub.github.com
            【解决方案11】:

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

            https://npmjs.org/package/pullr

            【讨论】:

            • 尝试在克隆的存储库中执行 pullr -n。在 Windows 7 上打开 .../clonedRepo/undefined/.pullr-token-cache 时给我一个错误。您可能想要更多文档 - 例如使用示例?
            【解决方案12】:

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

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

            【讨论】:

              猜你喜欢
              • 2012-02-04
              • 2019-12-08
              • 1970-01-01
              • 2015-04-19
              • 2021-08-29
              • 2019-02-04
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              相关资源
              最近更新 更多