Skip to content

Implement but stack#12000

Open
imskr wants to merge 1 commit intogitbutlerapp:masterfrom
imskr:imskr-but-stack
Open

Implement but stack#12000
imskr wants to merge 1 commit intogitbutlerapp:masterfrom
imskr:imskr-but-stack

Conversation

@imskr
Copy link
Copy Markdown

@imskr imskr commented Jan 24, 2026

🧢 Changes

  • Added but stack command to stack one branch onto another
  • Implemented stack_branch_onto_target function that removes and recreates a branch with a new anchor
  • Added validation to prevent stacking a branch onto itself
  • Added a check to prevent stacking the last-named branch in a stack (to avoid anonymous segments)
  • Preserved commit metadata when recreating the stacked branch

☕️ Reasoning

The but stack command provides a way to reorganize branch hierarchies by changing which branch another branch is stacked on top of. This is useful when you want to reorder your work or change dependencies between branches. The implementation safely removes the old branch reference while preserving its metadata, then recreates it with the target branch as its new anchor point. The validation ensures we don't create invalid states like anonymous stacks or circular dependencies.

🎫 Affected issues

Fixes: #11318

@vercel
Copy link
Copy Markdown

vercel Bot commented Jan 24, 2026

@imskr is attempting to deploy a commit to the GitButler Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions github-actions Bot added the rust Pull requests that update Rust code label Jan 24, 2026
@imskr
Copy link
Copy Markdown
Author

imskr commented Jan 24, 2026

Hello 👋🏻 @krlvi, I've created this for but stack. Could you give it a review? 🙇🏻

Copy link
Copy Markdown
Collaborator

@Byron Byron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HI! Thanks for giving it a shot!

Since I took a glimpse already, please let me point out a couple of things to be changed for the PR to have a chance to be merged. It would probably also be broken up into smaller pieces.

  • analysis/scope - what does it mean to stack a branch. The original instruction "Something like but stack that rebases my branch onto another into a stacked branch" isn't enough to get going here.
  • implement stacking in but-workspace and test it to death
  • wire it up in but (CLI) with a couple of tests for typical user interaction

I recommend closing this PR and doing a detailed analysis in the respective issue.

@imskr
Copy link
Copy Markdown
Author

imskr commented Jan 24, 2026

Thank you @Byron this helps. I would also like to get input from @krlvi on this PR, before working more to avoid wasting efforts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

rust Pull requests that update Rust code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement but stack

2 participants