How to git push an existing repository/project to Bitbucket Cloud
Platform Notice: Cloud Only - This article only applies to Atlassian products on the cloud platform.
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.
Solution
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.
1
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:
1
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.
1
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.
1
git push -u cloud --all && git push -u cloud --tags
Was this helpful?