Skip to main content

此版本的 GitHub Enterprise 已停止服务 2022-10-12. 即使针对重大安全问题,也不会发布补丁。 为了获得更好的性能、更高的安全性和新功能,请升级到最新版本的 GitHub Enterprise。 如需升级帮助,请联系 GitHub Enterprise 支持

Committing changes to a pull request branch created from a fork

You can commit changes on a pull request branch that was created from a fork of your repository with permission from the pull request creator.

You can only make commits on pull request branches that:

  • are opened in a repository that you have push access to and that were created from a fork of that repository
  • are on a user-owned fork
  • have permission granted from the pull request creator
  • don't have branch restrictions that will prevent you from committing

Only the user who created the pull request can give you permission to push commits to the user-owned fork. For more information, see "Allowing changes to a pull request branch created from a fork."

Note: You can also make commits to a pull request branch from a fork of your repository through your GitHub Enterprise Server instance by creating your own copy (or fork) of the fork of your repository and committing changes to the same head branch that the original pull request changes were created on. For some general guidelines, see "Creating a pull request from a fork."

  1. On GitHub Enterprise Server, navigate to the main page of the fork (or copy of your repository) where the pull request branch was created.

  2. 在文件列表上方,单击 “代� �”。 “代� �”按钮

  3. 复制存储库的 URL。

    • 要使用 HTTPS 克隆存储库,在“HTTPS”下单击
    • 要使用 SSH 密钥克隆存储库,包括组织的 SSH 证书颁发机构颁发的证书,请单击“SSH”,然后单击
    • 要使用 GitHub CLI 克隆存储库,请单击“GitHub CLI”,然后单击 用于复制 URL 以使用 GitHub CLI 克隆存储库的剪贴板图� �
  4. 打开终端终端Git Bash

    Tip: If you prefer to clone the fork using GitHub Desktop, then see "Cloning a repository to GitHub Desktop."

  5. Change the current working directory to the location where you want to download the cloned directory.

    $ cd open-source-projects
  6. Type git clone, and then paste the URL you copied in Step 3.

    $ git clone https://hostname/USERNAME/FORK-OF-THE-REPOSITORY
  7. Press Enter. Your local clone will be created.

    $ git clone https://hostname/USERNAME/FORK-OF-THE-REPOSITORY
     > Cloning into `FORK-OF-THE-REPOSITORY`...
     > remote: Counting objects: 10, done.
     > remote: Compressing objects: 100% (8/8), done.
     > remove: Total 10 (delta 1), reused 10 (delta 1)
     > Unpacking objects: 100% (10/10), done.

    Tip: The error message "fatal: destination path 'REPOSITORY-NAME' already exists and is not an empty directory" means that your current working directory already contains a repository with the same name. To resolve the error, you must clone the fork in a different directory.

  8. Navigate into your new cloned repository.

  9. Switch branches to the compare branch of the pull request where the original changes were made. If you navigate to the original pull request, you'll see the compare branch at the top of the pull request. compare-branch-example In this example, the compare branch is test-branch:

    $ git checkout TEST-BRANCH

    Tip: For more information about pull request branches, including examples, see "Creating a Pull Request."

  10. At this point, you can do anything you want with this branch. You can push new commits to it, run some local tests, or merge other branches into the branch. Make modifications as you like.

  11. After you commit your changes to the head branch of the pull request you can push your changes up to the original pull request directly. In this example, the head branch is test-branch:

    $ git push origin test-branch
    > Counting objects: 32, done.
    > Delta compression using up to 8 threads.
    > Compressing objects: 100% (26/26), done.
    > Writing objects: 100% (29/29), 74.94 KiB | 0 bytes/s, done.
    > Total 29 (delta 8), reused 0 (delta 0)
    > To https://hostname/USERNAME/FORK-OF-THE-REPOSITORY.git
    > 12da2e9..250e946  TEST-BRANCH -> TEST-BRANCH

Your new commits will be reflected on the original pull request on your GitHub Enterprise Server instance.

Further Reading