1

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?

TonyArra
  • 10,607
  • 1
  • 30
  • 46
renad sahal
  • 147
  • 10
  • What do you think a pull request will do? – evolutionxbox May 06 '22 at 14:15
  • I should do this to make reviewer able to see the code before merge it in master – renad sahal May 06 '22 at 14:16
  • 1
    You can't do this, period. A Pull Request is a different name for a Merge Request, and the result will be a merge. That's what a pull request does. If you have a few commits from branch `pull` that you'd like to add to `master` via a pull request, you'll have a create a new branch from `master`, cherry pick the relevant commits to it, and create a pull request from that. – joanis May 06 '22 at 14:31
  • `cherry pick the relevant commits to it` , should I push the code again to this branch ? or i have to choose some commit from `pull` branch ? there's a way to choose commit fast than push the code again ? – renad sahal May 06 '22 at 14:35

1 Answers1

1

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.

TonyArra
  • 10,607
  • 1
  • 30
  • 46