zlacker

[parent] [thread] 9 comments
1. jbjbjb+(OP)[view] [source] 2025-12-05 10:59:07
I think ‘git rebase —-update-refs’ is the better way to go for this scenario
replies(3): >>enbugg+26 >>leland+3i >>YmiYug+to
2. enbugg+26[view] [source] 2025-12-05 11:47:26
>>jbjbjb+(OP)
Is there any good guide on how to solve the issue which OP solves?
replies(2): >>sirsuk+1a >>jbjbjb+hp
◧◩
3. sirsuk+1a[view] [source] [discussion] 2025-12-05 12:15:59
>>enbugg+26
You don’t really need docs as --update-refs does what the OP does automatically instead of manually like the OP does.
replies(1): >>ptx+Gp
4. leland+3i[view] [source] 2025-12-05 13:06:17
>>jbjbjb+(OP)
Sweet, looks like this is pretty new (2022).

Running a git command on one branch and multiple branches being affected is really unusual for me! This really does look like it is designed for just this problem, though. Simple overview: https://blog.hot-coffee.dev/en/blog/git_update_refs/

5. YmiYug+to[view] [source] 2025-12-05 13:42:36
>>jbjbjb+(OP)
It breaks if you amend the top commit instead of adding a new one.
◧◩
6. jbjbjb+hp[view] [source] [discussion] 2025-12-05 13:47:41
>>enbugg+26
I was reading this the other day when I came across this feature because I’m stacking PRs recently which I don’t usually do

https://andrewlock.net/working-with-stacked-branches-in-git-...

Another commenter posted this link which was a bit more succinct

https://blog.hot-coffee.dev/en/blog/git_update_refs/

There isn’t much to it though, you just go to the branch and run git rebase with the update refs flag.

◧◩◪
7. ptx+Gp[view] [source] [discussion] 2025-12-05 13:49:36
>>sirsuk+1a
How? I tried recreating the scenario from the article (the section "First rebase –onto") and ran the first rebase with "--update-refs":

  $ git checkout feature-1
  $ git rebase --update-refs main
  Successfully rebased and updated refs/heads/feature-1.
  Updated the following refs with --update-refs:
   refs/heads/feature-2-base
But all it did was update feature-2-base. It still left feature-2 pointing to the old commits. So I guess it automates "git branch -f feature-2-base feature-1" (step 3), but it doesn't seem to automate "git rebase --onto feature-1 feature-2-base feature-2" (step 2).

Presumably I'm doing something wrong?

replies(2): >>happyt+fv >>mhw+iv
◧◩◪◨
8. happyt+fv[view] [source] [discussion] 2025-12-05 14:17:09
>>ptx+Gp
First, you don't need the extra "marker" commit. This flag obviates the entire workflow.

Second, you run it on the outermost branch: feature 2. It updates all refs in the chain.

◧◩◪◨
9. mhw+iv[view] [source] [discussion] 2025-12-05 14:17:17
>>ptx+Gp
Yeah, you need to rebase the tip of the feature branch stack. git will then update all the refs that point to ancestor commits that are moved. So in this case

    $ git rebase --update-refs main feature-2
replies(1): >>ptx+UA
◧◩◪◨⬒
10. ptx+UA[view] [source] [discussion] 2025-12-05 14:43:39
>>mhw+iv
Thanks! Yup, that does the trick.
[go to top]