title | intro | redirect_from | versions | topics | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Cloning a repository |
When you create a repository on {% data variables.location.product_location %}, 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. |
|
|
|
{% webui %}
You can clone a repository from {% data variables.location.product_location %} to your local computer{% ifversion codespaces %}, or to a codespace,{% endif %} 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 {% data variables.location.product_location %} to your local machine{% ifversion codespaces %}, or to a remote virtual machine when you create a codespace. For more information about cloning to a codespace, see "AUTOTITLE."{% else %}.{% endif %}
{% endwebui %}
{% cli %}
{% data reusables.repositories.about-cloning %}
{% endcli %}
{% desktop %}
{% data reusables.repositories.about-cloning %}
{% enddesktop %}
Cloning a repository pulls down a full copy of all the repository data that {% data variables.location.product_location %} 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 {% data variables.location.product_location %}, or pull other people's changes from {% data variables.location.product_location %}. For more information, see "AUTOTITLE".
You can clone your existing repository or clone another person's existing repository to contribute to a project.
{% webui %}
{% data reusables.repositories.navigate-to-repo %} {% data reusables.repositories.copy-clone-url %} {% data reusables.command_line.open_the_multi_os_terminal %} {% data reusables.command_line.change-current-directory-clone %} {% data reusables.command_line.git-clone-url %} {% data reusables.command_line.local-clone-created %}
{% endwebui %}
{% cli %}
{% data reusables.cli.cli-learn-more %}
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/PATH-TO/REPOSITORY
{% endcli %}
{% desktop %}
{% data reusables.repositories.navigate-to-repo %} {% data reusables.repositories.open-with-github-desktop %}
- Follow the prompts in {% data variables.product.prodname_desktop %} to complete the clone.
For more information, see "AUTOTITLE."
{% enddesktop %}
An empty repository contains no files. It's often made if you don't initialize the repository with a README when creating it.
{% data reusables.repositories.navigate-to-repo %}
-
To clone your repository using the command line using HTTPS, under "Quick setup", click {% octicon "copy" aria-label="Copy to clipboard" %}. To clone the repository using an SSH key, including a certificate issued by your organization's SSH certificate authority, click SSH, then click {% octicon "copy" aria-label="Copy to clipboard" %}.
Alternatively, to clone your repository in Desktop, click {% octicon "desktop-download" aria-hidden="true" %} Set up in Desktop and follow the prompts to complete the clone.
{% data reusables.command_line.open_the_multi_os_terminal %} {% data reusables.command_line.change-current-directory-clone %} {% data reusables.command_line.git-clone-url %} {% data reusables.command_line.local-clone-created %}
When cloning a repository it's possible that you might encounter some errors.
If you're unable to clone a repository, check that:
- You can connect using HTTPS. For more information, see "AUTOTITLE."
- You have permission to access the repository you want to clone. For more information, see "AUTOTITLE."
- The default branch you want to clone still exists. For more information, see "AUTOTITLE."
{% ifversion fpt or ghec %}
- "AUTOTITLE" {% endif %}