How to git push an existing repository/project to Bitbucket Cloud
Platform Notice: Cloud and Data Center - This article applies equally to both cloud and data center platforms.
Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.
*Except Fisheye and Crucible
Summary
In some scenarios, it might be necessary to migrate git repositories from other code hosting platforms, or even from a local machine, into Bitbucket Cloud. The goal of this page is to guide users on how to push an already existing git repository to Bitbucket Cloud.
Steps
- Go to bitbucket.org and make sure that a workspace and a repository has already been created, for example, workspace-example and repo-example. Please note that these names are just examples and should be changed to the actual name. Please use the documentation below to assist you on these steps:
- Mirror clone the repository, as the mirror clone contains all content of a repository:
Note that the <server-repo-url> variable should be changed to whatever platform you're cloning from, for example, Bitbucket Cloud is - git@bitbucket.org:workspace-example/repo-example.git for SHH and https://<BitbucketUsername>:<BitbucketAppPassword>@bitbucket.org/workspace-example/repo-example.git for HTTPS.
git clone --mirror <server-repo-url> temp
- The repository has been cloned into the "temp" directory as per the above command.
Move into "temp" folder:
cd temp
- Now that the repository was cloned using the --mirror flag, the remote-url needs to be changed.
The command below will create a "cloud" remote-url for the repository, and the <cloud-repo-url> should be changed to either SSH or HTTPS URL - git@bitbucket.org:workspace-example/repo-example.git for SHH and https://<BitbucketUsername>:<BitbucketAppPassword>@bitbucket.org/workspace-example/repo-example.git for HTTPS.
git remote add cloud <cloud-repo-url>
- The last step is to push all content of the mirror cloned repository to Bitbucket Cloud:
With the command below all content, including branches and tags, will be pushed to Bitbucket Cloud.
git push -u cloud --all && git push -u cloud --tags