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:-
- Created a clone of Gerrit repository on my local machine
- Created an empty repository in GitHub having primary branch
main
- Changed the remote URL of repository on local machine which was pointing to Gerrit and made it point to the repository on GitHub
- Created a replica of
master
branch and named itMainReplica
by usinggit checkout -b MainReplica
- Pushed this branch to remote by
git push -u origin MainReplica
which created a new branchMainReplica
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.