Home > Software design >  Migrating commit history from Gerrit to GitHub
Migrating commit history from Gerrit to GitHub

Time:08-01

I have an existing repository on Gerrit(On premise) which has master branch as primary branch and want to migrate this repository to GitHub(Cloud) with main as the primary branch having commit history exactly like I have on master branch in Gerrit. To accomplish this I have carried out the following steps:-

  1. Created a clone of Gerrit repository on my local machine
  2. Created an empty repository in GitHub having primary branch main
  3. Changed the remote URL of repository on local machine which was pointing to Gerrit and made it point to the repository on GitHub
  4. Created a replica of master branch and named it MainReplica by using git checkout -b MainReplica
  5. Pushed this branch to remote by git push -u origin MainReplica which created a new branch MainReplica on GitHub with the required commit history

Now I want to create a pull request on MainReplica to be merged into main because I cannot directly commit to main branch since it is protected. However, I am unable to see any option to created a pull request as it shows me a message There isn’t anything to compare. main and MainReplica are entirely different commit histories. Now I don't know how I can go about this, any suggestion would be really appreciated.

CodePudding user response:

If you want an "exact replica" of the history, then you are busted if you are not allowed to push (force push, in this case) into main. If you do not mind having a slightly different history, then merge the new repo's branch into your MainReplica locally:

git fetch origin
git checkout MainReplica
git merge --allow-unrelated-histories -m "merging branches from 2 repos" origin/main
git push origin @

Now you will be able to create the PR because origin/main is part of the history of MainReplica.

CodePudding user response:

You can rename a git branch via

git branch -m master main

and then you will have the very same commit history.

  • Related