Clone a Git repository to your local computer

When you clone a repository, a connection is created with a server and the files from the remote repository are downloaded to your computer.

This connection requires you to add credentials. You can either use SSH or HTTPS. SSH is recommended.

Clone with SSH

Clone with SSH when you want to authenticate only one time.

  1. Authenticate with GitLab by following the instructions in the SSH documentation.
  2. On the left sidebar, select Search or go to and find the project you want to clone.
  3. On the project’s overview page, in the upper-right corner, select Code, then copy the URL for Clone with SSH.
  4. Open a terminal and go to the directory where you want to clone the files. Git automatically creates a folder with the repository name and downloads the files there.
  5. Run this command:

    git clone <copied URL>
    
  6. To view the files, go to the new directory:

    cd <new directory>
    

You can also clone a repository and open it directly in Visual Studio Code.

Clone with HTTPS

Clone with HTTPS when you want to authenticate each time you perform an operation between your computer and GitLab. OAuth credential helpers can decrease the number of times you must manually authenticate, making HTTPS a seamless experience.

  1. On the left sidebar, select Search or go to and find the project you want to clone.
  2. On the project’s overview page, in the upper-right corner, select Code, then copy the URL for Clone with HTTPS.
  3. Open a terminal and go to the directory where you want to clone the files.
  4. Run the following command. Git automatically creates a folder with the repository name and downloads the files there.

    git clone <copied URL>
    
  5. GitLab requests your username and password.

    If you have enabled two-factor authentication (2FA) on your account, you cannot use your account password. Instead, you can do one of the following:

    If you have not enabled 2FA, use your account password.

  6. To view the files, go to the new directory:

    cd <new directory>
    
note
On Windows, if you enter your password incorrectly multiple times and an Access denied message appears, add your namespace (username or group) to the path: git clone https://namespace@gitlab.com/gitlab-org/gitlab.git.

Clone using a token

Clone with HTTPS using a token if:

  • You want to use 2FA.
  • You want to have a revocable set of credentials scoped to one or more repositories.

You can use any of these tokens to authenticate when cloning over HTTPS:

For example:

git clone https://<username>:<token>@gitlab.example.com/tanuki/awesome_project.git