Cloning a repository

When you create a repository on GitHub, it exists as a remote repository. You can clone your repository to create a local copy on your computer and sync between the two locations.

About cloning a repository

You can clone a repository from GitHub to your local computer to make it easier to fix merge conflicts, add or remove files, and push larger commits. When you clone a repository, you copy the repository from GitHub to your local machine.

Cloning a repository pulls down a full copy of all the repository data that GitHub has at that point in time, including all versions of every file and folder for the project. You can push your changes to the remote repository on GitHub, or pull other people's changes from GitHub. For more information, see "Using Git".

You can clone your existing repository or clone another person's existing repository to contribute to a project.

Cloning a repository

  1. 在 GitHub 上,导航到仓库的主页面。

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

  3. 要使用 HTTPS 克隆仓库,请在“Clone with HTTPS(使用 HTTPS 克隆)”下单击 . 要使用 SSH 密钥克隆仓库,包括由组织的 SSH 证书颁发机构颁发的证书,请单击 Use SSH(使用 SSH),然后单击 。 要使用 GitHub CLI 克隆仓库,请单击使用 GitHub CLI,然后单击 用于复制 URL 以克隆仓库的剪贴板图标

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

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

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

  6. 键入 git clone,然后粘贴先前复制的 URL。

    $ git clone https://github.com/YOUR-USERNAME/YOUR-REPOSITORY
  7. Enter 创建本地克隆。

    $ git clone https://github.com/YOUR-USERNAME/YOUR-REPOSITORY
    > 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.

To learn more about GitHub CLI, see "About GitHub CLI."

To clone a repository locally, use the repo clone subcommand. Replace the repository parameter with the repository name. For example, octo-org/octo-repo, monalisa/octo-repo, or octo-repo. If the OWNER/ portion of the OWNER/REPO repository argument is omitted, it defaults to the name of the authenticating user.

gh repo clone repository

You can also use the GitHub URL to clone a repository.

gh repo clone https://github.com/cli/cli
  1. 在 GitHub 上,导航到仓库的主页面。

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

  3. 单击 使用 GitHub Desktop 打开以使用 GitHub Desktop 克隆并打开仓库。 "使用 GitHub Desktop 打开"按钮

  4. Follow the prompts in GitHub Desktop to complete the clone.

For more information, see "Cloning a repository from GitHub to GitHub Desktop."

Cloning an empty repository

An empty repository contains no files. It's often made if you don't initialize the repository with a README when creating it.

  1. 在 GitHub 上,导航到仓库的主页面。

  2. To clone your repository using the command line using HTTPS, under "Quick setup", click . To clone the repository using an SSH key, including a certificate issued by your organization's SSH certificate authority, click SSH, then click . Empty repository clone URL button

    Alternatively, to clone your repository in Desktop, click Set up in Desktop and follow the prompts to complete the clone. Empty repository clone desktop button

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

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

  5. 键入 git clone,然后粘贴先前复制的 URL。

    $ git clone https://github.com/YOUR-USERNAME/YOUR-REPOSITORY
  6. Enter 创建本地克隆。

    $ git clone https://github.com/YOUR-USERNAME/YOUR-REPOSITORY
    > 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.

Troubleshooting cloning errors

When cloning a repository it's possible that you might encounter some errors.

If you're unable to clone a repository, check that:

Further reading

此文档对您有帮助吗?隐私政策

帮助我们创建出色的文档!

所有 GitHub 文档都是开源的。看到错误或不清楚的内容了吗?提交拉取请求。

做出贡献

或, 了解如何参与。