Clone a Git repository

Cloning a repository syncs it to your local machine. After you clone, you can add and edit files and then push and pull updates. 

This article refers to the command line. If you aren't familiar with the command line, check out our videos tutorials for your operating system:

Clone a repository using the command line

You can use Sourcetree, Git from the command line, or any client you like to clone your Git repository. These instructions show you how to clone your repository using Git from the terminal.

  1. From the repository, click + in the global sidebar and select Clone this repository under Get to work.

  2. Copy the clone command (either the SSH format or the HTTPS).
    If you are using the SSH protocol, ensure your public key is in Bitbucket and loaded on the local system to which you are cloning.

  3. From a terminal window, change to the local directory where you want to clone your repository.

  4. Paste the command you copied from Bitbucket, for example:

Clone over HTTPS

1 $ git clone https://username@bitbucket.org/teamsinspace/documentation-tests.git

Clone over SSH

1 $ git clone ssh://git@bitbucket.org:teamsinspace/documentation-tests.git

If the clone was successful, a new sub-directory appears on your local drive in the directory where you cloned your repository. This directory has the same name as the Bitbucket repository that you cloned. The clone contains the files and metadata that Git requires to maintain the changes you make to the source files.

Clone a repository with Sourcetree

You can also use Sourcetree to clone your repository. If you aren't familiar with Sourcetree, it's our client that provides an alternative to the command line. Follow these instructions to clone your repository. If you don't have SourceTree, download the application first.

  1. From the repository, select the Clone button.

  2. In the Clone this repository dialog, select the Clone in Sourcetree button.

  3. If necessary, update the Destination Path or Bookmark Name.

    1. The Destination Path is the folder where your clone saves to your local system.

    2. The Bookmark Name is the name of that folder.

  4. Select the Clone button.

Sourcetree creates the folder on your local system. You can use the Sourcetree to interact with the repository.

Screenshot of sourcetree cloned repo view with A through E callouts listed below

A. Branches list: Lists your Git branches.
B. Files list: Includes all the files in your repository.
C. Action buttons: Allows you to interact with the repository.
D. Commits list: Includes a list of commits to the repository and details of each commit.
E. Selected file: Shows a diff of the selected file.

Clone a repository with VS Code

You can also use Virtual Studio (VS) Code to clone your repository. If you aren't familiar with VS Code, it's a source code editor developed by Microsoft that provides an alternative to the command line. Follow these instructions to clone your repository. If you don't have Visual Studio Code, download the application first.

  1. From the repository, select the Clone button.

  2. In the Clone this repository dialog, select the Clone in VS Code button.

    1. If you have not already installed the Atlassian for VS Code extension, you will be prompted to install it. Select Install > select the Reload Window and Open button in the info dialog.

  3. In VS Code, select Clone a new copy from the dropdown menu.

  4. When prompted, select the local storage location where you want to keep the cloned repository. 

  5. Select the Select repository location button.

  6. Your repository will be cloned and stored in the location you chose. You can then open the repository and begin working on it in VS Code.

You may be prompted to log in to your Bitbucket Cloud account so VS Code can access the necessary data to clone your repository.

Last modified on Apr 1, 2021
Cached at 8:46 AM on Aug 4, 2021 |

Additional Help

Ask the Community