跳至主要内容

从 GitHub Desktop 克隆和分叉仓库

你可以使用 GitHub Desktop 克隆和分叉 GitHub 上存在的仓库。

平台导航

关于本地仓库

GitHub 上的仓库是远程仓库。你可以使用 GitHub Desktop 克隆或分叉仓库,以在你的计算机上创建本地仓库。

你可以通过克隆仓库来创建你在 GitHub 上有访问权限的任何仓库的本地副本。如果你拥有仓库或具有写入权限,则可以在本地和远程位置之间进行同步。有关更多信息,请参阅“在 GitHub Desktop 中同步你的分支”。

克隆仓库后,你推送到 GitHub 的任何更改都会影响原始仓库。若要进行更改而不影响原始项目,你可以通过分叉仓库来创建单独的副本。你可以创建一个拉取请求,建议维护者将你分叉中的更改合并到原始上游仓库中。有关更多信息,请参阅“关于分叉”。

当你尝试使用 GitHub Desktop 克隆你没有写入权限的仓库时,GitHub Desktop 会提示你自动创建一个分叉。你可以选择使用你的分叉来贡献原始上游仓库,或者独立地处理你自己的项目。任何现有的分叉都默认会将更改贡献到其上游仓库。你可以随时修改此选择。有关更多信息,请参阅“管理分叉行为”。

你还可以直接从 GitHub 或 GitHub Enterprise 克隆仓库。有关更多信息,请参阅“从 GitHub 克隆仓库到 GitHub Desktop”。

克隆仓库

  1. 在**文件**菜单中,单击**克隆仓库**。

    Screenshot of the menu bar on a Mac. The "File" dropdown menu is expanded, and the "Clone Repository" option is highlighted with an orange outline.

    Screenshot of the "GitHub Desktop" menu bar on Windows. The "File" dropdown menu is expanded, and the "Clone Repository" option is highlighted with an orange outline.

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

    Screenshot of the "Clone a repository" window. At the top of the window, tabs labeled "GitHub.com", "GitHub Enterprise" and "URL" are highlighted with an orange outline.

  3. 从仓库列表中,单击你要克隆的仓库。

    Screenshot of the "Clone a repository" window. The "github/docs" repository is highlighted with an orange outline.

  4. 要选择要克隆仓库的本地目录,请在“本地路径”字段旁边,单击**选择...**并导航到该目录。

    Screenshot of the "Clone a repository" window. A button, labeled "Choose", is highlighted with an orange outline.

  5. 在“克隆仓库”窗口底部,单击**克隆**。

分叉仓库

你可以在 GitHub 或 GitHub Desktop 上分叉仓库。有关在 GitHub 上分叉的信息,请参阅“分叉仓库”。

在 GitHub Desktop 中,如果你尝试克隆你没有写入权限的仓库,则会自动为你创建一个分叉。

  1. 在**文件**菜单中,单击**克隆仓库**。

    Screenshot of the menu bar on a Mac. The "File" dropdown menu is expanded, and the "Clone Repository" option is highlighted with an orange outline.

    Screenshot of the "GitHub Desktop" menu bar on Windows. The "File" dropdown menu is expanded, and the "Clone Repository" option is highlighted with an orange outline.

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

    Screenshot of the "Clone a repository" window. At the top of the window, tabs labeled "GitHub.com", "GitHub Enterprise" and "URL" are highlighted with an orange outline.

  3. 从仓库列表中,单击你要克隆的仓库。

    Screenshot of the "Clone a repository" window. The "github/docs" repository is highlighted with an orange outline.

  4. 要选择要克隆仓库的本地目录,请在“本地路径”字段旁边,单击**选择...**并导航到该目录。

    Screenshot of the "Clone a repository" window. A button, labeled "Choose", is highlighted with an orange outline.

  5. 在“克隆仓库”窗口底部,单击**克隆**。

  6. 阅读“你打算如何使用此分叉?”窗口中的信息。

    • 如果你计划将此分叉用于贡献原始上游仓库,请单击**贡献到父项目**。
    • 如果你计划将此分叉用于与上游无关的项目,请单击**用于我自己的目的**。
  7. 单击**继续**。

管理分叉行为

你可以在 GitHub Desktop 中更改分叉在上游仓库中的行为方式。

  1. 在菜单栏中,选择**仓库**,然后单击**仓库设置...**。

    Screenshot of the menu bar on a Mac. In the expanded "Repository" dropdown menu, a cursor hovers over "Repository Settings", highlighted in blue.

    Screenshot of the "GitHub Desktop" menu bar on Windows. In the open "Repository" dropdown menu, an option labeled "Repository Settings" is outlined in orange.

  2. 在“仓库设置”窗口的左侧边栏中,单击**分叉行为**。

  3. 在“我将使用此分叉...”下,使用单选按钮选择你想要如何使用分叉。

    Screenshot of the "Fork Behavior" pane. Two radio buttons, labeled "To contribute to the parent repository" and "For my own purposes", are outlined in orange.

  4. 单击**保存**。

为本地仓库创建别名

你可以为本地仓库创建别名,以帮助区分 GitHub Desktop 中同名仓库。创建别名不会影响仓库在 GitHub 上的名称。在仓库列表中,别名以斜体显示。

  1. 在 GitHub Desktop 的左上角,当前仓库名称右侧,单击.
  2. 右键单击你要为其创建别名的仓库,然后单击**创建别名**。
  3. 为仓库键入别名。
  4. 点击创建别名

进一步阅读