renad sahal
renad sahal

Reputation: 187

How can I create a pull request between branches with entirely different commit histories

I have two branches with entirely different commit histories, and I need to create a pull request - NOT MERGE - from one of them to the other. When I tried it gave me this: github error message for entirely different commit histories

I tried to push a mutual commit, but this is not working. What is the best practice for it? I'm a beginner and this is my first time dealing with it.

What should I do to create this pull request with all files contained in the pull branch?

Upvotes: 1

Views: 2539

Answers (1)

Tony Arra
Tony Arra

Reputation: 11119

It is possible to make a pull-request equivalent of git merge --allow-unrelated-histories. You can do it like so:

# First, create a new branch based on main:
git switch -c history-merge main

# Next, merge your branch with the unrelated history into `history-merge`
#
# Resolve any merge conflicts at this time,
# and change the merge text to "Merge branch 'unrelated' into main".
git merge unrelated --allow-unrelated-histories

# Push your new branch:
git push -u origin history-merge

Once that's done, you can create a pull request from history-merge into main.

If you want it to be 100% seamless, choose the rebase option when you go to merge the PR. This will fast-forward main to the original merge-commit.

Upvotes: 3

Related Questions