In this article, we will learn how to Migrate/Copy an existing Git repo from any source control providers (Github, Gitlab, Azure DevOps, etc..) into a new or empty existing repo.
Step 1. Clone the source repository
you can use any tool or IDE to clone your source repo. I am using the git bash tool. Run the git clone --mirror command, followed by Clone URL to clone your repo. When cloning using the mirror option, the cloned folder name includes a .git suffix.
git clone --mirror https://[your orgname].visualstudio.com/DefaultCollection/demo/_git/MigrationDemo
cd MigrationDemo.git
once you have your cloned completed, you can verify your fetch and push origin URL end-point, run the following command
git remote -v
now its time to update your local origin by the new repo URL.
Step 2. Change the remote URL to your new project repo URL
Update your origin for new repo end-point by running the below command
git remote set-url origin https://[your new orgname].visualstudio.com/DefaultCollection/test/_git/targetMigrationDemo
To see the untracked/unsynced changes for the new repo, run the following command
git remote show origin
Step 3. Push repo to new target location
git push origin --mirror
The --mirror option is used with both the clone and push command. The option ensures that all branches and other attributes are replicated in the new repo. it will overwrite all branches in the target repo which includes deleting any branches, not in the source repo.
You can verify your new repo with all the commit histories and comments etc.
Lastly, asked developers to update the source code repository link by using appropriate IDE or using below git bash command.
git remote set-url origin https://[your new orgname].visualstudio.com/DefaultCollection/test/_git/targetMigrationDemo
All Done!
There is another set of git commands to migrate the repo, run the following commands step by step to do that.
2. git remote rename origin old-origin
3. git remote add origin https://[your orgname].visualstudio.com/DefaultCollection/test/_git/targetMigrationDemo
4. git push -u origin --all
5. git push -u origin --tags
Conclusion:
I hope now you have learned something about basic git commands and migration of git repo.
Happy Learning! 😊
Good article!
ReplyDeleteVery Good......
ReplyDeleteGreat article.
ReplyDeleteThanks for sharing.
This is really good article ,we need frequently push data on production site once testing completed on development server ,its good if you will include Microsoft tfs site also their
ReplyDeletehttp://www.saraswatipgcollege.com
Nice
ReplyDeleteNice Job
ReplyDeleteGood one (Y)
ReplyDeleteGreat information!!
ReplyDeleteDevOps Services India
Cloud DevOps Services