gitbutler icon indicating copy to clipboard operation
gitbutler copied to clipboard

Feature request: stack multiple branches on top of one branch

Open shunichironomura opened this issue 1 month ago • 5 comments

I really love the stacked branch feature in GitButler.

However, one workflow that I sometimes use (and not possible in GitButler) is the following:

  1. Prepare a "base" branch for changes
  2. Create branches from the base branch per small change
  3. Merge those branches into the base branch
  4. Open a PR to merge the base branch into the main branch
  5. Have the base branch reviewed
  6. Merge the base branch into the main once approved.

To my knowledge, GitButler allows to stack only one branch on top of another branch, which makes the above workflow infeasible.

shunichironomura avatar Oct 30 '25 03:10 shunichironomura

Thanks a lot for reporting!

While GitButler has many shortcomings related to deliberately merging branches locally, it can have stacks of any size. Here is an example, and I created it using the right-click menu to create a branch above another one.

Image

I am probably missing something though, maybe you can elaborate or provide a video of what you are trying to do with GitButler? Maybe it's a bug you are running into? Thank you.

Byron avatar Oct 30 '25 04:10 Byron

Sorry for the insufficient description. I forgot to mention that I assumed the use of GitHub pull request to merge the feature branches.

I was thinking that being able to make two independent pull requests (st-branch-44 into to-be-dragged-into, and independent into to-be-dragged-into in your example) on GitHub would be nice. Basically, doing the equivalent of following:

* 62ae26c 2025-10-30  (HEAD -> feature-2) Add feature-2.txt
| * a2f6e4b 2025-10-30  (feature-1) Add feature-1.txt
|/
* 587fa27 2025-10-30  (base) Add base.txt
* 3740b2e 2025-10-30  (main) Add main.txt

But now I realize that maybe the GitButler's approach is to stack two feature branches linearly and then either:

  • Drag the changes locally to "merge" the feature branches
  • Or, order the feature virtual branches in the stack as needed and then create pull requests?

shunichironomura avatar Oct 30 '25 04:10 shunichironomura

Thanks for elaborating!

I think I understand now, and you'd want to create PRs for feature1 into base and feature2 into base. And actually, this scenario you can create.

Image

These stacks I created manually by checking to-be-dragged-into out in Git, and creating a new branch on top of it. After applying that to the workspace, it looks like this, and creating PRs from the segments on top of to-be-dragged-into will want to merge them back into it.

After merging both on GitHub and clicking the 'fetch' button, it's definitely slightly confused about what happened, and we'd have to resolve it manually probably by deleting the top-branches manually.

Image

After having done that, we are left with insufficient ways to 'integrate' the upstream changes - we want a fast-forward.

Image

The integration capabilities are definitely something revise as well, it's on the list.

As far as this issue is concerned, I think it can be left open as the overall workflow isn't great yet, unless of course one wants to run a whole 'update-workspace' which may or may not work.

Byron avatar Oct 30 '25 07:10 Byron

Thank you for the detailed walk-through! I successfully reproduced it locally.

However, it was not easy to do it correctly. I share my log for record.

# Create repository locally and on GitHub
mkdir gb-multiple-branches
cd $_
git init
gh repo create --public --source=.

# Create main branch and push
touch main.txt
git add main.txt
git commit -m "Add main.txt"
git push

# Create base branch and push
git switch -c base
touch base.txt
git add base.txt
git commit -m "Add base.txt"
git push

# Create feature-1 branch based off base and push
git switch -c feature-1
touch feature-1.txt
git add feature-1.txt
git commit -m "Add feature-1.txt"
git push

# Create feature-2 branch based off base and push
git switch base
git switch -c feature-2
touch feature-2.txt
git add feature-2.txt
git commit -m "Add feature-2.txt"
git push

# Open the repo in GitButler
# Click 'continue' to switch to workspace
# Apply feature-1 to workspace -> feature-2 is on the base branch, but feature-1 is not (See the first image)
git switch feature-1
git switch base
git branch -D feature-1 # Delete the local feature-1 as feature-1 was rebased by GitButler?
git switch feature-1 # Checkout feature-1 again from remote
# Open the repo in GitButler -> Success! feature-1 and feature-2 are both on the base branch (See the second image)

First attempt (feature-1 is not on the base branch): Image

Second attempt (both feature-1 and feature-2 are on the base branch): Image

shunichironomura avatar Oct 30 '25 09:10 shunichironomura

Right, sorry for that!

I am using the new version of 'apply branch' which doesn't rebase, so it's easier to work with, usually (even though it's not ready for prime time yet).

Byron avatar Oct 30 '25 09:10 Byron