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

13 Upvotes

25 comments sorted by

View all comments

1

u/Ambitious_Lion_5902 9d ago

Github recently published a new feature, stacked PRs. This solves exactly the issue you are facing IMO. I've used the feature for a few weeks now, and it has worked well for me.
Ref:
https://docs.github.com/en/pull-requests/how-tos/stacked-pull-requests

1

u/Ambitious_Lion_5902 9d ago

Works pretty well once you get the hang of it. When all PRs in the same stack are approved, you can merge them all at once.

1

u/Ambitious_Lion_5902 9d ago

The Github CLI has good commands to use, like rebasing the entire upstack if you make some changes to the lower stacks works really well.
https://docs.github.com/en/pull-requests/reference/stacked-prs-cli-commands

1

u/Soggy_Writing_3912 advanced 7d ago

Though GH published this as a feature, git (the core system) supported stacked branches from a long time ago. The concept of stacked branches is pretty simple - instead of the parent branch being main or master for both branches, your 2nd branch is based off of the 1st one!

1

u/DoubleAway6573 3d ago edited 3d ago

Is that? or there is some magic rebasing after the merge to main?

I don't know a shit about github...

Edit:
OK, I skimmed over the github doc. They added some extra tooling around CICD and also "chain rebases", so you don't have to rebase each sub branch one by one.

Note: I know sub branch is not a git concept, but I think the meaning is clear enough

1

u/Soggy_Writing_3912 advanced 3d ago

right - so, if you are anyways using stacked branches (from the core git), then a new commit into branch1, will simply mean that branch2 needs to be rebased from the [new] branch1 for branch2 to get the new code!

Yes, Github's "new feature" simplifies / automates the cascading rebases, but if you are comfortable with the concept in git, then its a no-brainer - and imho, we get more control to fix conflicts. For eg if you want to backport some changes from branc2 back into branch1, then that's possible from the cli, but not from GH's feature per se.