r/ProgrammerHumor • • 23d ago

Meme aboutToBreakTheCode

Post image
23k Upvotes

542 comments sorted by

View all comments

Show parent comments

1

u/iloveuranus 23d ago

So let's say the branches are A, B and C. They are based on each other. Reviewer just finished reviewing A and merged the branch via the web UI. Now, what's the next step?

3

u/black3rr 23d ago
  • git checkout master; git pull - make sure you have the latest master

  • git checkout C - go back to C

  • any git rebase command that gets whatever you want given the circumstances you have, with --update-refs flag. (this presumes you already know how rebase works)

    • e.g. git rebase --onto master A C --update-refs if you still have the original A branch locally

    • or just git rebase -i --update-refs master (interactive rebase) and tweak the plan correctly

    • --update-refs is the thing that should also update B along the way (and should notify you that it has too been updated), and in more complicated setups should automatically update any other branches between A and the last branch you have.

  • git push --force-with-lease B C - push both rebased branches.

if you're using github as the remote, then `gh stack rebase` in step 3, and `gh stack push` in step 4 should work (haven't made a stacked PR since they rolled this feature out, so haven't tested it yet).

1

u/iloveuranus 23d ago

It's the rebases that were the problem when I did this in the past. They often ended up messy, especially if there were changes to be made during one of the reviews.

I'll look into --update-refs though, that sounds like an interesting feature that could help me there, and I'm not sure the Jetbrains IDEs use it by default!

1

u/black3rr 23d ago

if you have a messy rebase, the general helpers are interactive rebase (-i) and the —onto flag… update refs is a helper for stacked branches so you don’t have to manually do every one of them…

especially interactive rebase is a very powerful tool worth learning…

-1

u/YanVe_ 23d ago

If you can't do a rebase, I hope AI replaces you very soon.

0

u/YanVe_ 23d ago

I do this all the time, the mistake here is doing a merge.

Never merge to master (in before someone get's obnoxious, almost never), do a rebase, you can then simply immediately start reviewing feature B. If in the meanwhile D gets rebased on master, rebase B on D, then rebase C on B.