Clone a repository

Cloning a repository

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:
     $ git clone https://username@bitbucket.org/teamsinspace/documentation-tests.git
    Clone over SSH:
    $ git clone 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.

Cloning a mirror repository

You can use SourceTree, Git from the terminal, or any client you like to clone your Git repository. These instructions show you how to clone a mirrored repository using Git from the terminal. Read more about Smart Mirrors

 

  1. Navigate to the repository in Bitbucket.
  2. Click the Clone button.
  3. If mirrors are configured, use the Clone from dropdown to select the mirror closest to you–the clone URL changes.
  4. Copy the clone URL (either SSH or HTTPS).
    If you are using the SSH protocol, ensure your public key is correctly configured. 
  5. Launch a terminal window.
  6. Change to the local directory where you want to clone your repository.
  7. Enter git clone followed by the copied clone URL.
    The command and clone URL together would look like this:

    $ git clone ssh://git@bitbucket-au.example.com:7999/upstream/PROJ/repo.git

If the clone was successful, a new sub-directory appears on your local drive. 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.

You cannot push to a mirror!

Mirrors are read-only. After cloning from a mirror, you must update your remote push URL to point to the primary Bitbucket Data Center instance.

Update your remote push URL

Since you cannot push to a mirror, after cloning from a mirror you need to update your remote push URL to point to the primary (upstream) instance.

To update your push URL

  1. In the repository on Bitbucket Server, click the Clone button.
  2. Select a mirror in the Clone from dropdown, then copy the command that looks like this:

    git remote set-url --push origin ssh://git@bitbucket.example.com:7999/PROJ/repo.git

  3. In the terminal, navigate to the cloned directory then run the command.

Your remote push URL now points to the primary Bitbucket Data Center instance.

Update your remote push URL in SourceTree

Since you cannot push to a mirror, after cloning from a mirror you need to update your remote push URL to point to the primary (upstream) instance within SourceTree.

To update your push URL in SourceTree
  1. In the repository on Bitbucket Server, click Clone.
  2. Select a mirror in the Clone from dropdown, then copy the command that looks like this:

    git remote set-url --push origin ssh://git@bitbucket.example.com:7999/PROJ/repo.git

    You won't need the commands, only the push URL (the bit that starts after ssh://).

  3. Within SourceTree, open your repository settings.
  4. Select the origin repository path, then click Edit Config File...
    A text editor appears. 
  5. Within the Config File, under [remote "origin"], enter pushurl = then paste only the push URL after =.
    The config file should look like this:

    pushurl = ssh://git@bitbucket.example.com:7999/PROJ/repo.git
  6. Save and close the Config File. Click OK to close the Repository Settings screen.

Your remote push URL within SourceTree now points to the primary Bitbucket Data Center instance.

Last modified on Jan 6, 2016

Was this helpful?

Yes
No
Provide feedback about this article
Powered by Confluence and Scroll Viewport.