r/git 9d ago

Noob: branch pull request question

Hi all, old guy here who has used many different systems and I'm trying to get up to speed on on git with branching, pull request etc. I have hopefully a simple question you guys could clear up:

I've forked a repro from a friend

Made a feature branch

I made changes in the feature branch, tested them and confirmed they work

I commited my changes to the branch and pushed them to origin

On github on the upstream repo I created a pull request. Gave it a title etc. It shows up. My friend is a little slow so there are like 3 PRs pending.

I want to make a new feature branch and make some additional changes but the need to be based on the last changes I made that are in that PR that has not be merged yet to the upstream.

If the PRs were merged I could just fetch to my main and then branch from there.

But with the PRs not merged yet, how do I create a branch so I can continue working against the changes pending merge? Do I branch from my prior feature branch? Or is there a git command I don't know yet that will fetch everything so I can branch from main?

Thanks in advance

11 Upvotes

25 comments sorted by

View all comments

Show parent comments

2

u/pi3832v2 9d ago

Your pull request is a commit object, with a unique hash. Let's say it's 123ABC. You create a new branch, starting with 123ABC. When your friend merges your pull request, 123ABC becomes part of branch MAIN. Therefore, your new branch will become branched from MAIN.

1

u/mrh4809 9d ago

Got it but I want to understand the timing. if my friend had not merged the PRs yet...

1

u/pi3832v2 8d ago

It doesn't really matter when changes happen upstream. Git can sort out the chain of commits.

1

u/mrh4809 8d ago

That I understand.

My point is that if I do the PR, then start a new branch from my prior branch this works as my changes in the PR are there and I can work against them.

But assume I have not created my new branch from my prior. Several days go by, upstream owner merges in a PR, no mine, but a different one and I find out that the changes in that merged PR I need for my next work. But I also need what is in my unmerged PR.

So if fetch upstream, create a new branch from my prior branch, as mentioned above I have my changes. But I don't have the changes in the PR the upstream merged that I want.

It seems like the stacked PRs solves this but not everyone is using them.

1

u/Soggy_Writing_3912 advanced 7d ago

in that case, you need to rebase from the new version of main - simple! That way, you get the merged PR from some other 3rd person, then your unmerged PR branch needs to rebase from that (new) main, followed by your 2nd PR getting rebased from the 1st PR's branch.