How to Migrate Code Between Git-Based Source Code Repositories
--
In this story, we will discuss how to migrate between Git-Based Source Code Repositories, such as Bitbucket, Azure DevOps, GitHub, GitLab, and any Git-based source code repository.
Migrating Git Code Repositories
Here is the procedure to migrate repos between any Git-based source code repositories:
- Optional step: Create the destination Git repo if it does not exist.
- Optional step: Install the git tools (if not installed) on your computer from https://git-scm.com/downloads/guis.
- Open the command line or console on your computer.
- Authenticate to both Git-based source and destination code repositories.
- Change to a temp folder used to store the content of the source Git repo and execute the following code:
git clone --mirror <source_git_repo_address>
6. Change to the repo folder created (ended in .git) and then type the following command to remove the remote origin from the Git Repository:
git remote rm origin
7. After that, we add the destination repository as the origin with the following command:
git remote add origin <destination_gt_repo_address>
8. Finally, we push the code to the destination Git repo with the following command:
git push --mirror
or
git push origin --all
git push --tags
Example of Migrating Git Code Repositories
Here is an example of a migration from Azure DevOps to GitHub using the procedure above:
D:\> cd d:\migration
D:\migration> git clone --mirror https://dev.azure.com/KopiCloud/_git/terraform-kopicloud-ad-api-adgroup
Cloning into bare repository 'terraform-kopicloud-ad-api-adgroup.git'...
remote: Azure Repos
remote: Found 86 objects to send. (107 ms)
Unpacking objects: 100% (86/86), 14.98 KiB | 1024 bytes/s, done.
D:\migration> cd D:\migration\terraform-kopicloud-ad-api-adgroup.git
D:\migration\terraform-kopicloud-ad-api-adgroup.git> git remote rm origin
Note: Some branches outside the…