A short and useful post today, recently we had a customer requirement to migrate their git repositories from one account to another service provider, for example moving from bitbucket to GitHub, the repositories had a history of branches and commit for over 5 years and were quite huge in size.
The solution was quite simple but I thought to document this for anyone who is looking to solve a similar problem.
Step 1 is to mirror the Git repository to your local machine by the following command
$ git clone --mirror https://url-of-the-source-git-repo.git
The above command would create a directory with your repository name.git format for example myproject.git
Step 2 is to create a new repository on the destination server with the same name (not required though)
Step 3 is set the remote repository URL, run the command from inside your git repo folder
$ cd to-your-git-repo-folder.git $ git remote set-url --push origin https://url-of-the-destination-git-repo.git
Step 4 is to push the repository to the destination
$ git push --mirror
By running the following commands you can migrate the complete Git repository with all Commit history and Branches.
Hope you find this post useful, please leave a comment for any questions or suggestions.
DataNext Solutions is a US based system integrator, specialized in Cloud, Big Data, DevOps technologies. As a registered AWS partner, our services comprise of any Cloud Migration, Cost optimization, Integration, Security and Managed Services. Click here and Book Free assessment call with our experts today or visit our website www.datanextsolutions.com for more info.
Originally published at datanextsolutions.com on October 10, 2018.