如何使用命令行 git 接受来自 Github 的拉取请求 (PR)
How to accept pull requests (PR) from Github using command line git
问题
我收到了一个拉取请求,我想通过命令行批准它(即,不使用我的浏览器登录 Github 并使用 GUI)。此 PR 对分支进行更改。
这是我试过的:
# First I go to the correct branch:
git checkout branch-to-be-modified
# Then I pull the changes made by the person who's contributing with the PR:
git pull https://github.com/my-contributor/code.git his-branch
# I then run `git status`, but it shows me nothing
git status
# Outputs:
# > On branch branch-to-be-modified
# > nothing to commit, working tree clean
问题
如何通过命令行接受 Github 拉取请求?
我还需要做什么,我应该 git push origin branch-to-be-modified
吗?
这应该很容易,但我找不到这些信息。非常感谢您提供任何线索
你应该要求 GitHub 合并所述拉取请求:那将是“接受”它。
您可以从命令行执行此操作,使用 gh
, the official GitHub client
gh pr merge <number>
但这假设您首先登录(例如,使用像您的 PAT: gh auth login --with-token < mytoken.txt
这样的令牌)。
同样,从命令行,不直接使用 GitHub web。
您可以拥有 2 个遥控器,origin
和 fork
。从那里你可以从 fork 分支合并到你的分支。然后提交并推送到原点。
拉取请求是 Github 特定的功能。 Git 独立于 Github,您不会在 Git 中找到任何 Github 特定的功能。如果你想在没有网络浏览器的情况下接受 PR,你需要寻找 Github 工具,例如 Github Desktop or Github CLI. These are all wrappers around the Github REST API and Github GraphQL API.
您可以像对待任何其他远程分支一样手动合并 PR 分支,并且 PR 应该识别其分支已被合并。但是 Pull Requests can be about a lot more than just merging 所以你可能想使用 Github 工具。
每个项目都可以merge their Pull Requests in different ways:合并、压缩合并或变基。您将不得不模仿项目的合并策略。幸运的是,Git PR 会告诉您如何做到这一点。如果 Merge pull request 按钮旁边有一个 link 用于“查看命令行说明”。
单击它并按照说明进行操作。
大意是:
- 获取远程分支。
- 如果它在分叉的存储库中,您需要将该分叉添加为远程。
- 从他们的远程分支创建一个本地分支。
- 合并master到本地分支。
- 这将产生与将本地分支合并到 master 中相同的代码。
- 测试分支。
- 如果通过,则使用适当的合并方法将分支合并到 master。
- 推送你当地的高手。
有关更多信息,请阅读 Github 上的 Working With Remotes in Pro Git and Working With Forks。
问题
我收到了一个拉取请求,我想通过命令行批准它(即,不使用我的浏览器登录 Github 并使用 GUI)。此 PR 对分支进行更改。
这是我试过的:
# First I go to the correct branch:
git checkout branch-to-be-modified
# Then I pull the changes made by the person who's contributing with the PR:
git pull https://github.com/my-contributor/code.git his-branch
# I then run `git status`, but it shows me nothing
git status
# Outputs:
# > On branch branch-to-be-modified
# > nothing to commit, working tree clean
问题
如何通过命令行接受 Github 拉取请求?
我还需要做什么,我应该 git push origin branch-to-be-modified
吗?
这应该很容易,但我找不到这些信息。非常感谢您提供任何线索
你应该要求 GitHub 合并所述拉取请求:那将是“接受”它。
您可以从命令行执行此操作,使用 gh
, the official GitHub client
gh pr merge <number>
但这假设您首先登录(例如,使用像您的 PAT: gh auth login --with-token < mytoken.txt
这样的令牌)。
同样,从命令行,不直接使用 GitHub web。
您可以拥有 2 个遥控器,origin
和 fork
。从那里你可以从 fork 分支合并到你的分支。然后提交并推送到原点。
拉取请求是 Github 特定的功能。 Git 独立于 Github,您不会在 Git 中找到任何 Github 特定的功能。如果你想在没有网络浏览器的情况下接受 PR,你需要寻找 Github 工具,例如 Github Desktop or Github CLI. These are all wrappers around the Github REST API and Github GraphQL API.
您可以像对待任何其他远程分支一样手动合并 PR 分支,并且 PR 应该识别其分支已被合并。但是 Pull Requests can be about a lot more than just merging 所以你可能想使用 Github 工具。
每个项目都可以merge their Pull Requests in different ways:合并、压缩合并或变基。您将不得不模仿项目的合并策略。幸运的是,Git PR 会告诉您如何做到这一点。如果 Merge pull request 按钮旁边有一个 link 用于“查看命令行说明”。
单击它并按照说明进行操作。
大意是:
- 获取远程分支。
- 如果它在分叉的存储库中,您需要将该分叉添加为远程。
- 从他们的远程分支创建一个本地分支。
- 合并master到本地分支。
- 这将产生与将本地分支合并到 master 中相同的代码。
- 测试分支。
- 如果通过,则使用适当的合并方法将分支合并到 master。
- 推送你当地的高手。
有关更多信息,请阅读 Github 上的 Working With Remotes in Pro Git and Working With Forks。