pileofrogs
pileofrogs

Reputation: 152

Can I change the base branch of a PR in github?

Last week I created a branch from "main" that I'll call "A" and I made a PR. While I waited for my co-workers to review my PR I started another branch from "A", that I'll call "B". I did some more work and created a 2nd PR. The second PR wants to merge changes from "B" into "A". I would have liked to do "B" into "main" but I can't do that because "B" contains "A" and "A" has it's own PR.

Now a few days later, "A" has been merged into "main". My 2nd PR is "B" into "A", but what I really want is "B" into "main" because "A" has been merged into "main" and "A" doesn't exist any more on origin.

Is it possible to change my PR so instead of being "B" into "A" it's "B" into "main"? I've already had a few review comments and I'd rather preserve that. I don't want to open a new PR with the same changes.

Also, "A" wasn't merged into "main" as "A". "A" was split into two different PRs, so while the changes in "A" were merged into "main", "A" itself was never literally merged into "main". I don't know if that makes any difference.

Thanks!

PS: I looked and while I saw similar questions, I never saw one that answered my actual question. People either wanted to know how to make a PR "B" into "A" which I've already done or they were happy to make a new PR, which I'm not.

Upvotes: 2

Views: 161

Answers (1)

VonC
VonC

Reputation: 1326782

You should be able to rebase B onto master, making it independent of A.
Then a force push of B will update the existing PR for B.

That is:

m--m--m--m---m (main)
    \       /
     a--a--a   (A)
         \
          b--b (B)

git rebase --onto main $(git merge-base A B) B

               b'--b' (B rebased)
              /
m--m--m--m---m (main)
    \       /
     a--a--a   (A)

Upvotes: 2

Related Questions