dimitrieh 2 hours ago
  • ndr an hour ago

    The main issue I kept having when trying to do this with just git is then managing all the branch names to be attached to the right moved commits, so that my stack could be reviewable on github's open PRs.

    Does jj help with that at all?

    I've experimented a bit with git-town.com (OSS) and now everyone at $DAYJOB uses graphite.com (SaaS) which does that part very well.

    • baq an hour ago

      It’s one of the core features that rebases, including branch names (bookmarks in jj) work ‘correctly’. You can rebase whole dags, including merges, with multiple named heads with just one jj rebase -b.

      • arccy 26 minutes ago

        note that bookmarks don't float, unlike git branches, so if your pattern is to produce a lot of commits, you'll want something to keep your jj bookmarks pointing to the top of your pile of commits.

        this is less of a problem if you're more into the 1 change == 1 commit workflow.

        • pimeys 22 minutes ago

          There's a very common alias `jj tug` for this case:

            tug = ["bookmark", "move", "--from", "heads(::@- & bookmarks())", "--to", "@-"]
          
          It moves the nearest bookmark to the commit before the current one (which should be your working commit).
        • lima 24 minutes ago

          There's an experimental-advance-branches feature which helps with that!

happytoexplain 8 minutes ago

Even if `--update-refs` didn't exist, my experience is that git can identify duplicate commits produced by rebase, and knows to skip them when rebasing the same commits to the same place again. Am I imagining that?

nopurpose an hour ago

That particular case can be solved much easier by rebasing outer-most branch with `--update-refs` flag.

  • happytoexplain 16 minutes ago

    I came into the comments specifically to ask if this flag existed. I feel bad that the author developed this whole flow just because they didn't know about this, but that's pretty common with git.

  • imron 42 minutes ago

    Yep. I set this in .gitconfig

dspillett 19 minutes ago

For the example given, would merging branch 2 into branch 1 then branch 1 into main achieve the same effect?

Perhaps not an option if you need to release the work in branch 1 before the work in branch 2 is ready/reviewed/etc.

  • happytoexplain 12 minutes ago

    The point of this technique is to keep them separate. See the other comments about `--update-refs`.

jbjbjbjb 2 hours ago

I think ‘git rebase —-update-refs’ is the better way to go for this scenario

  • enbugger an hour ago

    Is there any good guide on how to solve the issue which OP solves?

    • sirsuki 24 minutes ago

      You don’t really need docs as --update-refs does what the OP does automatically instead of manually like the OP does.

the_gipsy 2 hours ago

I usually just `git rebase origin/main -i` after the base branch has been merged there, and this means I need to explicitly drop the merged commits, but I can inspect what's happening.

ragebol 32 minutes ago

Ah, I've been doing this for ages but apparently this practice has a name

perspectivezoom 2 hours ago

I'm a heavy user of git-spice: https://abhinav.github.io/git-spice (created by a former coworker) and can't really go back to a time without it. While still not nearly as good as Facebook's Phabricator, it's probably the best workflow for small, focused stacked PRs you can achieve in a Github / Gitlab based repository.

politelemon an hour ago

This marker branch step feels like a workaround to a missing capability. It's something I can easily see one forgetting especially if they haven't been doing stacked diff workflows regularly.

  • imron 40 minutes ago

    The capability is there.

    Just use git rebase --update-refs ...

  • sublinear an hour ago

    I agree it seems error prone. I'm not sure if I'm misunderstanding something, but I use `git cherry-pick` when I know I need to move commits around that might have conflicts. The problem with rebase can be that the user doesn't fully understand all the options being applied and end up with a "bad" merge.

    I don't usually want to rewrite history. I just want the target branch with all my commits on top (I usually squash the feature branch into one commit anyway). I have yet to run into a situation where this isn't good enough.

    If the branch diverges so much and has so many commits that this simpler approach doesn't work, that might not be a git problem, but a project management one. It's still always nice to know git has tools to get me out of a jam.

hahahacorn 2 hours ago

I consider myself a shmedium experienced dev who likes to learn their tools and read source.

This seems like a house of cards whose juice isn’t worth the squeeze. But I would love to split up my PRs into smaller pieces.

I just would hate to waste time with an incomprehensibly goofed git history because I forgot a command.

nrhrjrjrjtntbt an hour ago

Fun stuff, but I'll stick to trunk based dev, small PRs... thanks!

  • taejavu an hour ago

    Stacking commits lets you do that without having to wait for each change to be reviewed/merged to the main branch before you iterate on top of those changes.

    • nrhrjrjrjtntbt 43 minutes ago

      True. I find I rarely need it: standard rebase or merge do the trick. If they don't the review cycle or PR size may be too high. Super rare I need onto. So rare I look up how to do it when I do.

sockbot an hour ago

We use graphite at work to automate this workflow. The whole point is avoid this toil.