Skip to main content


Learn how to contribute to a project through forking.

About forking

After using GitHub by yourself for a while, you may find yourself wanting to contribute to someone else’s project. Or maybe you’d like to use someone’s project as the starting point for your own. This process is known as forking.

Creating a "fork" is producing a personal copy of someone else's project. Forks act as a sort of bridge between the original repository and your personal copy. You can submit pull requests to help make other people's projects better by offering your changes up to the original project. Forking is at the core of social coding at GitHub. 更多信息请参阅“复刻仓库”。


This tutorial uses the Spoon-Knife project, a test repository that's hosted on that lets you test the fork and pull request workflow.

  1. Navigate to the Spoon-Knife project at
  2. Click Fork. 复刻按钮
  3. GitHub AE will take you to your copy (your fork) of the Spoon-Knife repository.

Cloning a fork

You've successfully forked the Spoon-Knife repository, but so far, it only exists on GitHub AE. To be able to work on the project, you will need to clone it to your computer.

You can clone your fork with the command line, GitHub CLI, or GitHub Desktop.

  1. 在 GitHub AE 上,导航到 Spoon-Knife 仓库的复刻

  2. 在文件列表上方,单击 ****Code(代码)。 "代码"按钮

  3. 要使用 HTTPS 克隆仓库,请在“Clone with HTTPS(使用 HTTPS 克隆)”下单击 . To clone the repository using an SSH key, including a certificate issued by your organization's SSH certificate authority, click Use SSH, then click . To clone a repository using GitHub CLI, click Use GitHub CLI, then click . 用于复制 URL 以克隆仓库的剪贴板图标

    用于复制 URL 以使用 GitHub CLI 克隆仓库的剪贴板图标

  4. 打开 Terminal(终端)Terminal(终端)Git Bash

  5. 将当前的工作目录更改为您想要存储克隆目录的位置。

  6. 键入 git clone,然后粘贴先前复制的 URL。 它将如下所示,使用您的 GitHub AE 用户名替换 YOUR-USERNAME

    $ git clone https://主机名/YOUR-USERNAME/Spoon-Knife
  7. Enter 键。 将创建您的本地克隆。

    $ git clone https://主机名/YOUR-USERNAME/Spoon-Knife
    > Cloning into `Spoon-Knife`...
    > 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.

要了解有关 GitHub CLI 的更多信息,请参阅“关于 GitHub CLI”。

要创建复刻的克隆,请使用 --clone 标记。

gh repo fork repository --clone=true
  1. File(文件)菜单中,单击 Clone Repository(克隆仓库)

    Mac 应用程序中的克隆菜单选项

    Windows 应用程序中的克隆菜单选项

  2. 单击与要克隆的仓库位置对应的选项卡。 您也可以单击 URL 手动输入仓库位置。

    克隆仓库菜单中的 Location(位置)选项卡

    克隆仓库菜单中的 Location(位置)选项卡

  3. 从列表中选择要克隆的仓库。



  4. 单击 Choose...(选择...)并找到要克隆仓库的本地路径。



  5. 单击 Clone(克隆)



Making and pushing changes

Go ahead and make a few changes to the project using your favorite text editor, like Atom. You could, for example, change the text in index.html to add your GitHub username.

When you're ready to submit your changes, stage and commit your changes. git add . tells Git that you want to include all of your changes in the next commit. git commit takes a snapshot of those changes.

git add .
git commit -m "a short description of the change"
git add .
git commit -m "a short description of the change"

For more information about how to stage and commit changes in GitHub Desktop, see "Committing and reviewing changes to your project."

When you stage and commit files, you essentially tell Git, "Okay, take a snapshot of my changes!" You can continue to make more changes, and take more commit snapshots.

Right now, your changes only exist locally. When you're ready to push your changes up to GitHub AE, push your changes to the remote.

git push
git push

For more information about how to push changes in GitHub Desktop, see "Pushing changes to GitHub."

Making a pull request

At last, you're ready to propose changes into the main project! This is the final step in producing a fork of someone else's project, and arguably the most important. If you've made a change that you feel would benefit the community as a whole, you should definitely consider contributing back.

To do so, head on over to the repository on GitHub AE where your project lives. For this example, it would be at<your_username>/Spoon-Knife. You'll see a banner indicating that your branch is one commit ahead of octocat:main. Click Contribute and then Open a pull request.

GitHub AE will bring you to a page that shows the differences between your fork and the octocat/Spoon-Knife repository. 单击 Create pull request(创建拉取请求)

GitHub AE will bring you to a page where you can enter a title and a description of your changes. It's important to provide as much useful information and a rationale for why you're making this pull request in the first place. The project owner needs to be able to determine whether your change is as useful to everyone as you think it is. Finally, click Create pull request.

Managing feedback

Pull Requests are an area for discussion. In this case, the Octocat is very busy, and probably won't merge your changes. For other projects, don't be offended if the project owner rejects your pull request, or asks for more information on why it's been made. It may even be that the project owner chooses not to merge your pull request, and that's totally okay. Your copy will exist in infamy on the Internet. And who knows--maybe someone you've never met will find your changes much more valuable than the original project.

Finding projects

You've successfully forked and contributed back to a repository. Go forth, and contribute some more!