Import code from an existing project
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.
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.
- 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.
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 Repository setup page.
- Choose I have an existing project.
- 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
- Create an empty repository in Bitbucket.
- Open a shell on your local machine (GitBash terminal for Windows users).
Verify your SSH key is working.
$ ssh -T email@example.com
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
tutorialsaccount. 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.)
Navigate to the root directory of the repository you want to push.
$ cd ~/repos/originalrepo
Push the local repo up to Bitbucket
$ git push --mirror firstname.lastname@example.org:tutorials/exploratory
This command pushes your local repository to the Bitbucket server.
If you want, you can push several branches at once to your Bitbucket repository. To do this, do the following:
- Checkout each branch to your local repository from your existing Git host.
List all the branches to make sure you have what you want:
$ git branch -a
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://email@example.com/youraccount/reponame.git
Then push all the branches to Bitbucket:
$ git push -u origin --all
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 TortoiseHg Workbench was introduced in version 2.0. If you don't have this version of TortoiseHg, you can upgrade. Alternatively, you can:
- Change to the root of your Mercurial repository.
- Change to the
- Edit the
- Edit the default value making sure to specify the address of the empty repository you created in Step 1.
- Save and close the file.
- Push the repository.
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.
Was this helpful?
Thanks for your feedback!