Git Clone | Create a copy of an existing Git repository – GitKraken

Updated on: 6/15/2022 The

Git clone is used to copy an existing Git repository to a new local directory. The Git clone command creates

a new local directory for

the repository,

copies all contents of the specified repository, creates the remote tracking branches, and checks out an initial branch locally. By default, the Git clone will create a reference to the remote repository named origin.

How

to clone a Git repository To clone a Git repository, navigate to

your preferred repository hosting service like GitHub, select the repository you want to clone, copy the repository URL via HTTPS or SSH, type git clone at the command line, paste the URL, and press enter

.

Cloning a repository allows you to make local changes to the repository before committing them and pushing them to the remote repository.

This can be especially beneficial for beginning developers, as cloning gives you a sandbox to experiment with without affecting the original codebase (and angering your team members 😅). In this article, we will take an in-depth look at how to clone Git from the command line in GitKraken Client and from the GUI.

Git Clone topics covered Git Remote Repository URL Protocols Git Remote Protocol SSH Git Remote Protocol

HTTP (S) Remote Protocol

How to clone Git over HTTPS using the command line How to clone Git over SSH using GitKraken Client How to clone Git

over HTTPS using

GitKraken Client Clone Git with GitKraken Client Client integrations Git Clone FAQs about Git

Clone

GitKraken Client

makes

clone

easy

Git Remote

Git Repository URL Protocols

The supported protocols for remote URLs in Git are SSH, Git, HTTP, and HTTPS.

Git Remote Protocol

SSH

SSH stands for Secure Shell. Using Git SSH allows you to authenticate with a remote repository using a key.

Format of an SSH URL: ssh://{user}@{host}:{port}/path/to/repo.git

or {user}@host:path/to/repo.git To use Git

SSH on the command line, you’ll need to generate a public and private SSH key, add the key

to your SSH agent, and add the public key to the remote hosting service

. Git Remote Protocol The Git protocol

is an unauthenticated method and should be used with caution.

Format of a

Git

URL:

git://{host}:{port}/path/to/repo.git

HTTP Remote Protocol(S)

HTTP(S)

stands for Hypertext Transfer Protocol (Secure). Using HTTPS allows you to authenticate with the repository using user name and password credentials.

Compared to HTTP, HTTPS is a more secure version.

Format of an HTTPS URL: https://{host}:

{port}/path/to/repo.git

GitTip: Learn more about local Git repositories and remote repositories with our series of beginner Git tutorial videos

. How to clone Git over HTTPS using the command line In this example, we’ll go over the process of cloning a

GitHub

repository

over HTTPS. To clone a Git repository, you’ll first copy the remote URL of your repository hosting service, in this case GitHub.

Next, you’ll use the Git clone command followed by the remote repository URL.

git clone <repository-url>

If you are working with a private repository, you will be prompted for the credentials of the remote hosting service

.

After cloning, you can change the directories (cd <path>) in the repository to start working on it. There are many additional flags that can be used when cloning for things like naming the local directory, naming the remote control, or unprotecting a branch.

How to clone

Git over SSH using GitKraken Client

If you are using a URL to clone over SSH with GitKraken Client, you will first need to configure Git SSH on the Git client. GitKraken Client has a built-in SSH agent that makes working with SSH keys, including SSH keys from GitHub, a breeze.

The SSH

settings of the GitKraken Client can be found in Preferences > SSH. Here, you can generate a new SSH key, point to an existing key, or use your local SSH agent to manage SSH.

If this is your first time using SSH through the GitKraken Client, you will need to add the SSH key to the remote hosting service, in this case, GitHub. You’ll simply copy the public key from the GitKraken Client and add it in the settings section of your hosting service.

Once you’ve completed those steps, you’ll be able to simply provide the SSH URL to clone remote repositories with the GitKraken Client.

For more information about working with SSH in the GitKraken Client, see our Git SSH documentation. GitHub also has a great guide on how to work with SSH.

How to clone Git over HTTPS using GitKraken Client If you are using a URL to clone over HTTPS with GitKraken Client, simply provide the remote URL when prompted.

Here, you will also set the local path to clone and the directory name of the local repository.

Git Clone integrations with

GitKraken Client GitKraken

Client offers integrations for the following remote repository hosting services

to perform cloning

, as

well as many other actions, even easier:

GitHub GitHub Enterprise GitLab

  • Self-managed Bitbucket
  • GitLab Bitbucket
  • Server

  • Azure DevOps

As seen below, each hosting service integration you have connected to your GitKraken Client account will list all remote repositories available for cloning.

HTTPS is the default remote protocol in the GitKraken Client. After connecting to your remote repository hosting service, you won’t be prompted to fill in your credentials while working over HTTPS, as the integration uses OAuth or a PAT (personal access token) to authenticate.

For each of these integrations, you can quickly create an SSH key or point to an existing one. Generating an SSH key will automatically add it to the hosting service, eliminating the need to manually copy it from one platform and add it to another.

You can manage your GitKraken Client integrations at any time by navigating to Preferences > Integrations. In this example, you can see that the GitKraken Client is creating a GitHub SSH key.

Alternatively, if you want to point to an existing SSH key, you can add the public SSH key to the hosting service with a single click.

Frequently asked questions

Q: How to clone a Git repository A: If you want to clone an existing Git repository

, navigate to the repository you want to clone to your preferred code hosting service like GitHub or GitLab and select clone with SSH or HTTPS.

Q: How to clone Git A: Git

is distributed version control software that allows you to keep track of projects. It’s unlikely you’ll run into a situation where you want to clone Git. Instead, with Git, you can clone a Git repository from a hosting service like GitHub, GitLab, and others via SSH or HTTPS. For more advanced cloning options, such as using git clone -shared, git clone -no checkout, and more, visit Git SCM.

GitKraken client makes it easy to clone

Git

The more your Git wallet grows, the harder it is to manage your remote repository library. The GitKraken Git client can help organize your remotes from multiple hosting services, giving you the ability to quickly find and clone the repository you need.

Contact US