Import code from an existing project

Redirection notice

This page will redirect to /bitbucket/import-or-convert-code-from-an-existing-tool-795937450.html .

Learn how to get your existing code into Bitbucket Cloud quickly from another hosting site or your local system.

Use the importer in Bitbucket to grab a repository from another hosting site.

Or learn how to create and push your first DVCS repository, or push an existing Git or Mercurial repository from your local system to Bitbucket.

This page

Related pages

Git Tutorial
Everything to get someone new to Git and Bitbucket going.

Getting Git Right
All about Git from beginner to advanced workflows. 

Converting from another version control system

If you have an SVN repository you'd like to convert to either Git or Mercurial see one of the following:

Import from a hosting site or project using the importer

You can import from popular code hosting sites like GitHub or SourceForge, or from Git, Google Code, Mercurial or Subversion repositories, via the Bitbucket importer. The importer cannot convert Git repositories to Mercurial repositories or vice versa. When you import code from an external Git or Mercurial repository, the importer simply creates a clone of the repository which is then hosted in Bitbucket.

Bitbucket does not host Subversion repositories. When you import from a Subversion repository, the importer:

  • exports a working copy of your trunk code base
  • builds a new DVCS repository
  • commit the entire working copy as a single DVCS changeset into the new repository on Bitbucket.

Bitbucket does not retain the history when importing code from Subversion.  If you would like to retain your Subversion revision history in Bitbucket, you must perform an offline synchronization. This may take a long time to complete and be CPU intensive, depending on the size of your repository, the number of revisions, branches and tags in your repository.

To import code do this.

  1. Choose Repositories > import repository from the menu bar.
  2. Select the Source of the code you want to import. 
  3. Depending on the Source, the system asks you to provide the following information:

    Source Information you must supply
    CodePlex URL, Project name, Repository type
    Git/GitHub URL, a Username/Password combination for private repositories that Require authorization
    Google Code URL, Project name, Repository type
    Mercurial URL, a Username/Password combination for private repositories that Require authorization
    SourceForge URL, Project name, Repository type
    Subversion URL, a Username/Password combination for private repositories that Require authorization
  4. Enter a Name for your new repository.
  5. Uncheck Private if you want the repository to be Public.
  6. Select a Language
  7. Click Issue tracking and/or Wiki if you want those features.
  8. Enter a Description and Website if you wish.
  9. Press Import.

Import an existing, unversioned code project to an empty repository

If you have code on your local machine that is not under source control, you can put it under source control and import it into Bitbucket. To do this:

  1. Locally, change to the root directory of your existing source.
  2. Initialize the directory under source control.

    Git Hg
    git init

    hg init .

  3. Add the existing files to the repository.

    Git Hg
    git add .

    hg add .

  4. Commit the files.

    Git Hg
    git commit -m "message"

    hg commit -m "message"

  5. Log into Bitbucket.
  6. Create a new repository.
  7. Locate the Repository setup page.
  8. Choose I have an existing project.
  9. Follow the directions in the pane for your repository.

Uploading or pushing a Git or Mercurial project to an empty repository

You can upload an existing repository to a empty project in Bitbucket. When you do this, Bitbucket maintains your commit history.

Pushing a Git project

This kind of push overwrites the contents of the Bitbucket repository. You should use it with great caution.

  1. Create an empty repository in Bitbucket.
  2. Open a shell on your local machine (GitBash terminal for Windows users).
  3. Verify your SSH key is working.

    $ ssh -T
    conq: logged in as tutorials.

    You can use git or hg to connect to Bitbucket. Shell access is disabled.

    The message should report you are logged in as your Bitbucket account. In this example, my ssh key was on my tutorials account. If you don't get this message, stop and troubleshoot your SSH connection to Bitbucket. (See Use the SSH protocol with Bitbucket Cloud for information about doing this.)

  4. Navigate to the root directory of the repository you want to push.

    $ cd ~/repos/originalrepo
  5. Push the local repo up to Bitbucket

    $ git push --mirror

    This command pushes your local repository to the Bitbucket server.

Push Several Branches at Once

If you want, you can push several branches at once to your Bitbucket repository. To do this, do the following:

  1. Checkout each branch to your local repository from your existing Git host.
  2. List all the branches to make sure you have what you want:

    $ git branch -a
  3. Make sure the remote origin in your local repository points to Bitbucket.
    For example, if you are using ssh with Bitbucket, you would use the following:

    $ git remote set-url origin ssh://
  4. Then push all the branches to Bitbucket:

    $ git push -u origin --all

Pushing a Mercurial project

This kind of push overwrites the contents of the Bitbucket repository. You should use it with great caution.

  1. Create a new, empty repository on Bitbucket.
  2. Go to your local machine and start the TortoiseHg Workbench.
  3. Select the repository you want to push from the Repository Registry.
  4. Choose File > Settings from the menu bar.
    The TortoiseHg Settings dialog appears. It includes a tab for your global settings and a tab for the repository you selected.
  5. Select the tab for the repository settings.
  6. Click Edit File.
  7. Change the default value.
    This value is the repository on Bitbucket you want to push to:
  8. Press Save to save your edits and close the file.
  9. Press OK to close the settings.
  10. Press Push outgoing changes to selected URL.
No TortoiseHg Workbench Available?

The TortoiseHg Workbench was introduced in version 2.0. If you don't have this version of TortoiseHg, you can upgrade.  Alternatively, you can:

  1. Change to the root of your Mercurial repository.
  2. Change to the .hg subdirectory.
  3. Edit the hgrc file.
  4. Edit the default value making sure to specify the address of the empty repository you created in Step 1.
  5. Save and close the file.
  6. Push the repository.


The following users contributed tutorials that provided information which improved this page. Thank you.

After I redid this page, I deleted the old comments that no longer applied. You can find them here as an attachment.


Was this helpful?

Thanks for your feedback!

Why was this unhelpful?

Have a question about this article?

See questions about this article

Powered by Confluence and Scroll Viewport