lazygit icon indicating copy to clipboard operation
lazygit copied to clipboard

Stacked PRs in lazygit

Open canadaduane opened this issue 1 year ago • 2 comments

Is your feature request related to a problem? Please describe.

I'm interested in incorporating stacked PRs into a lazygit workflow:

https://benjamincongdon.me/blog/2022/07/17/In-Praise-of-Stacked-PRs/ https://timothya.com/blog/git-stack/

I don't yet have a clear vision of how this would work in lazygit, but the overarching goal is to be able to make several related, simultaneous pull requests (each with 1 or more commits) in Github (or similar). Given feedback from the PRs, I'd like a way to edit the commits within PRs, or re-sequence the PRs in lazygit, or omit / introduce new PRs in between existing PRs.

Describe the solution you'd like This is more of a "call for ideas" than a concrete solution. Has the concept of stacked PRs been discussed? Are there existing solutions that work well with lazygit? Would it make sense to use a command like git-stack, or would a custom implementation specific to lazygit make more sense?

Additional context I'm exploring command-line tools like gh-stack, git-stack, and git-branchless. There are also possibly-commercial options out there such as graphite (gt).

canadaduane avatar Mar 29 '23 21:03 canadaduane

I haven't worked with tools like git-stack myself; when I work with stacked branches, I manage them manually. The introduction of git rebase --update-refs in 2.38 made that actually feasible, before it was a pain in the butt.

Before thinking about adding features to manage stacked branches to lazygit, we first need to fix a few basic things that are broken right now:

  1. When typing "e" to start a rebase on the selected commit, lazygit breaks the stack. The reason is that it creates a git-rebase-todo file itself instead of letting git create one, and it doesn't know how to insert update-ref commands.
  2. When initiating a rebase outside of lazygit to work around this, editing rebase todos is broken. The reason is that lazygit assumes it shows as many rebase todos as there are lines in the git-rebase-todo file, which is not true when there are update-ref commands in the file. This means that using ctrl-j/k will move the wrong commits. Because of this, you need to be very careful when using lazygit with stacked branches, and rebase.updateRefs set to true.

I'm working on fixing both of these right now (2nd first).

After that, the next think I'm missing is to somehow visualize the individual branch heads of the stack in the local commits panel. They are visible when you expand the panel using +, just not when the panel is not expanded. I don't have a good idea how, there's not enough room to draw the branch names, but I'd be ok with somehow visualizing that there is a branch at a given commit, not necessarily which one; maybe just by coloring the commit differently, or putting some icon before the subject, something like that. Ideas welcome, I'm not a good designer.

Once all these are done, I'd be happy and wouldn't need any more support for working with stacked branches. But that's only my personal opinion, others might disagree.

stefanhaller avatar Apr 03 '23 10:04 stefanhaller

The two issues mentioned above are fixed in the 0.38 release, so support for stacked branches is a lot better now.

Visualization of branch heads in the local commits view is not great yet. You have to opt in to it by turning on the gui.experimentalShowBranchHeads config, then it shows branch heads with a (*) annotation. However, it also shows these for remote branches, which is undesirable. We still need to iterate on this some more, but it's a start.

There are a few remaining issues for me:

  • Undoing a rebase operation on a branch stack only resets the top of the stack, not the other branch heads. This is a tricky one to solve, as the undo feature is based entirely on the HEAD reflog.
  • Pushing the individual branches of a stack is tedious; you have to checkout and push each one individually, would be nice if there's an easier way to do that.
  • Visualization of branch heads in the commits list needs to be improved, as mentioned above.

If you have other issues with support for stacked branches besides there, I'd be interested to hear about them.

stefanhaller avatar May 03 '23 08:05 stefanhaller

I love that lazygit is working toward support for these types of workflows!

If you have other issues with support for stacked branches besides there, I'd be interested to hear about them.

I think it would be nice if the local branches visualization showed a tree view that reflected the stack of branches. For example, graphite's gt log short visualization looks something like this:

  ◯      feature-c
  │ ◉    feature-b-3
  │ ◯    feature-b-2
  │ ◯    feature-b
  │ │ ◯  feature-a
  ◯─┴─┘  main

Another thing I'd love to have from a stacked branch feature set is integration with worktrees. e.g., instead of operating on the branches in the stack only in the current worktree, move to the existing worktree location for each branch during the operation.

lettertwo avatar Sep 15 '23 18:09 lettertwo