Let’s discuss about how we can migrate from BitBucket to Forgejo (self hosted git server).It works with any git server.
Back Story
I have more than 20 repositories in BitBucket back when there is no support for private repositories in Github. Since BitBucket provided private repos I used it extensively for all my personal projects.
Later GitHub provided private repos and I’m using that from then on.
Fast forward from 10 years to now, I want to consolidate all my repositories into one place and I have a personal Git server using Forgejo and I would like to move all repos from BitBucket to Forgejo.
Quirks
I have checked in Forgejo migration UI for BitBucket but it is not available.
I checked if any effort is made into making a migration for BitBucket and there is an issue for that but it is not being actively worked upon.
Getting data from BitBucket
At first try to setup SSH access for BitBucket
Generating SSH Key using ssh-keygen
Replace <username> with your actual username from BitBucket or use any other file name of your choiceOne can use a different algorithm and use password for SSH key for more security.
|
|
Now we will end up with private and public keys which is called key pair.
Copy the public key
|
|
Note:
- Copy the entire public key even dashes
- Replace <username> with your username or your public key file name
Setup SSH key in BitBucket
Goto Settings (Top right in UI)-> Personal BitBucket Settings -> SSH keys
Click on Add Key
A modal popup comes up
Give the SSH key a name and paste the public key from previous step in to public key fieldYou might want to give it an expiry to limit dangling SSH keys to have access
Once SSH key is setup properly try to see if that is working
|
|
Successfully logged into BitBucket
Setup SSH Hosts for easy access
Copy below information into your ssh config (~/.ssh/config)
|
|
Note: Replace <path to your bitbucket private key> with your original path
Then we can test it using
|
|
Setup repository from BitBucket
Change directory to any folder you want to clone into
|
|
Change the remote url as we would push this repository into different git server
|
|
Note: Setup remote url while being in git repository
Now check if the url is set properly
|
|
Uploading to new Git server
|
|
Above command works for single branch but I found out for repos with multiple branches it is not working.
Trials
|
|
|
|
|
|
All of the above didn’t work with multiple branches
Solution for multiple branches upload
|
|
Now check on new git server if all branches are migrated.
Conclusion
There is an option in Forgejo migration UI for importing git repository. If you have couple of repositories then we can use UI to migrate.
I choose this approach because I have many repositories and want to automate it using a script and that can be used for other Git servers as well in future
Note: Above method might not migrate issues but I don’t have any issues in my repositories so I’m good for now.
Research Links
Below are the websites I used for my migration effort