Retarget PR, force push, and manage draft state atomically
Retargets PR, force pushes rebased changes, and manages draft state atomically.
/plugin marketplace add settlemint/agent-marketplace/plugin install crew@settlemintgit/stacked/<butler_context>
!${CLAUDE_PLUGIN_ROOT}/scripts/git/gitbutler-context.sh
</butler_context>
<pr_info>
!${CLAUDE_PLUGIN_ROOT}/scripts/git/gh-pr-info.sh 2>&1
</pr_info>
<stack_context>
!${CLAUDE_PLUGIN_ROOT}/scripts/git/machete-context.sh 2>&1
</stack_context>
<gitbutler_incompatible>
This command does not work with GitButler.
If GITBUTLER_ACTIVE=true from <butler_context>:
Stacked branches (git-machete) are not compatible with GitButler virtual branches.
GitButler has its own stacking system. Use these instead:
- `crew:git:butler:status` - View virtual branches
- `crew:git:butler:branch` - Create virtual branch
- `crew:git:butler:sync` - Sync with upstream
To use machete, first disable GitButler in this repository.
Exit immediately. Do not proceed with machete commands.
</gitbutler_incompatible>
<objective>Atomically retarget a PR, force push rebased changes, and manage draft state.
</objective> <workflow>branch=$(git branch --show-current)
pr_number=$(gh pr view --json number -q '.number' 2>/dev/null || echo "")
current_base=$(gh pr view --json baseRefName -q '.baseRefName' 2>/dev/null || echo "")
machete_parent=$(git machete show up 2>/dev/null || echo "main")
echo "Branch: $branch"
echo "PR #: $pr_number"
echo "Current base: $current_base"
echo "Machete parent: $machete_parent"
local_sha=$(git rev-parse HEAD)
remote_sha=$(git rev-parse origin/$branch 2>/dev/null || echo "none")
if [[ "$local_sha" != "$remote_sha" ]]; then
echo "Local has unpushed changes"
git log --oneline origin/$branch..HEAD 2>/dev/null | head -5
fi
AskUserQuestion({
questions: [
{
question: "Restack will retarget PR and force push. Continue?",
header: "Restack",
options: [
{
label: "Yes with draft (Recommended)",
description: "Set to draft, restack, then ready",
},
{ label: "Yes without draft", description: "Restack immediately" },
{ label: "Cancel", description: "Don't restack" },
],
multiSelect: false,
},
],
});
With draft state:
gh pr ready --undo $pr_number 2>/dev/null || true
git machete github retarget-pr
git push --force-with-lease origin $branch
gh pr ready $pr_number
Without draft:
git machete github restack-pr
git config machete.github.prDescriptionIntroStyle full
git machete github update-pr-descriptions --related
gh pr view --json state,mergeable,baseRefName -q '{state: .state, mergeable: .mergeable, base: .baseRefName}'
gh pr checks
</workflow>
<success_criteria>
</success_criteria>