Hello,
I came across this article showing how to importing GIT repositories from other hosting services. I was wondering, if there's a way to automate this with scripting?
Thank you and best,
G.W.
The steps necessary to "import" a repo to any platform, Bitbucket included, is to:
These steps would need to know what credentials to use for the initial clone as well as the creds for pushing into the new remote (since they'll likely differ) as well as knowing the URLs for the source and destination. All of this should be possible in bash or really any scripting language that can interact with CLI for the purpose of calling git operations.
Example:
source_username = ""
source_password = ""
source_repo_url = ""
destination_username = ""
destination_password = ""
destination_repo_name = ""
destination_project_key = ""
destination_workspace_slug = ""
# clone the repo
git clone --mirror https://$source_username:$source_password@source_repo_url temp
# create empty placeholder in destination workspace
curl -u "$destination_username:$destination_password" -X POST -H "Content-Type: application/json" -d '{ "scm": "git", "project": { "key": $destination_project_key } "https://api.bitbucket.org/2.0/repositories/$destination_workspace_slug/$destination_repo_name"
# explore into repo dir
cd temp
# add new remote
git remote add cloud https://$destination_username:$destination_password@bitbucket.org/$destination_workspace_slug/$destination_repo_name.git
# push to new remote
git push -u cloud --all
git push -u cloud --tags
Then you'd just need to loop it if there's multiple repos that you want to migrate, passing in the source_url and the repo name/project key for each itteration.
You can see an example of this in python for migrating from GitHub to Bitbucket Cloud here
Hi Michael,
This is really helpful. Thank you! I have a question about the username format in the curl command: should it just be my email address verbatim?
Best,
G.W.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
For the Bitbucket (destination) side of things, you'll need your username (not email address)
For the password, I'd recommend just using an app password as they can be used for git operations (clone/push) as well as interacting with the REST API (the curl command). You could also use an access token but that's probably an unnecessary added complication since app passwords work great for this sort of thing.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I think we could replicate the steps one way or another.
Operations like creating the repository are supported by the Bitbucket API, and moving the content would be a series of git operations.
Since you have to check out the repository first, it's not as direct as importing with Bitbucket cloud, but workable.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.