When creating a new repository, you can import code from an existing project into Bitbucket. You can do this using the Bitbucket importer or you can do this by pushing code from your local system to an empty Bitbucket repository.
If you are interested in migrating away from Subversion to Mercurial and bringing your history along, see Goodbye Subversion, Hello Mercurial: A Migration Guide in Atlassian Blogs.
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:
- Locally, change to the root directory of your existing source.
Initialize the directory under source control.
hg init .
Add the existing files to the repository.
git add .
hg add .
Commit the files.
git commit -m "message"
hg commit -m "message"
- Log into Bitbucket.
- Create a new repository.
- Locate the Getting Started panel.
- Choose I have code I want to Import.
- Follow the directions in the pane for your repository.
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.
- Choose Repositories > import repository from the menu bar.
- Select the Source of the code you want to import.
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
- Enter a Name for your new repository.
- Uncheck Private if you want the repository to be Public.
- Select a Language.
- Click Issue tracking and/or Wiki if you want those features.
- Enter a Description and Website if you wish.
- Press Import.
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
- Create an empty repository in Bitbucket.
- Open a shell on your local machine (GitBash terminal for Windows users).
Verify your SSH key is working.
The message should report you are logged in as your Bitbucket account. In this example, my ssh key was on my
tutorialsaccount. If you don't get this message, stop and troubleshoot your SSH connection to Bitbucket. (See Use the SSH protocol with Bitbucket for information about doing this.)
Navigate to the root directory of the repository you want to push.
Push the local repo up to Bitbucket
This command pushes your local repository to the Bitbucket server.
Pushing a Mercurial project
- Create a new, empty repository on Bitbucket.
- Go to your local machine and start the TortoiseHg Workbench.
- Select the repository you want to push from the Repository Registry.
- 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.
- Select the tab for the repository settings.
- Click Edit File.
- Change the
This value is the repository on Bitbucket you want to push to:
- Press Save to save your edits and close the file.
- Press OK to close the settings.
- Press Push outgoing changes to selected URL.
The following users contributed tutorials that provided information which improved this page. Thank you.
- alombarte who wrote a tutorial which provided information for me to write this.
- Eli Spizzichino who also wrote a tutorial.
After I redid this page, I deleted the old comments that no longer applied. You can find them here as an attachment.