Skip to content

Instantly share code, notes, and snippets.

@itdhsc
Last active August 11, 2026 08:31
Show Gist options
  • Select an option

  • Save itdhsc/b13f9c223ca235b5281b4ed2e05bc36c to your computer and use it in GitHub Desktop.

Select an option

Save itdhsc/b13f9c223ca235b5281b4ed2e05bc36c to your computer and use it in GitHub Desktop.
Lazygit GitHub Stack Custom Command
# Fetch remote updates, rebase the stack onto the latest base, and push changed layers.
# Works best when stack branches use the `stack/` prefix, e.g. `stack/my-feature`.
customCommands:
- key: '#'
description: 'gh stack'
commandMenu:
- key: 'h'
description: 'Handle stack state'
commandMenu:
- key: 'i'
context: 'global'
description: 'Start a new stack │ [init] Initialize from the current branch'
command: 'gh stack init "$(git branch --show-current)"'
output: popup
- key: 'o'
context: 'global'
description: 'Open an existing stack │ [checkout] Select by stack, PR, or branch'
command: 'gh stack checkout'
output: terminal
- key: 'a'
context: 'global'
description: 'Add the next layer │ [add] Create a branch above the current layer'
prompts:
- type: 'input'
title: 'New stack branch name'
key: 'Branch'
initialValue: '{{ runCommand "git branch --show-current | sed \"s#^stack/##\"" }}-'
command: 'gh stack add {{.Form.Branch | quote}}'
output: popup
- key: 's'
context: 'global'
description: 'Sync local and remote │ [sync] Reconcile, rebase, push, and sync PR state'
command: 'gh stack sync'
output: terminal
after:
checkForConflicts: true
- key: 'v'
context: 'global'
description: 'Understand the stack │ [view] Show its layers and current position'
command: 'gh stack view'
output: popup
- key: 'r'
context: 'global'
description: 'Reorganize the stack │ [modify] Interactively change its structure'
command: 'gh stack modify'
output: terminal
after:
checkForConflicts: true
- key: 'g'
description: 'Go to another layer'
commandMenu:
- key: 'j'
context: 'global'
description: 'Jump to any layer │ [switch] Open the interactive branch picker'
command: 'gh stack switch'
output: terminal
- key: 't'
context: 'global'
description: 'Go to the top │ [top] Highest layer'
command: 'gh stack top'
output: popup
- key: 'u'
context: 'global'
description: 'Go one layer up │ [up]'
command: 'gh stack up'
output: popup
- key: 'd'
context: 'global'
description: 'Go one layer down │ [down]'
command: 'gh stack down'
output: popup
- key: 'b'
context: 'global'
description: 'Go to the bottom │ [bottom] Layer closest to trunk'
command: 'gh stack bottom'
output: popup
- key: 'u'
description: 'Update and review'
commandMenu:
- key: 'r'
context: 'global'
description: 'Rebase the whole stack │ [rebase] Update from trunk through the top'
command: 'gh stack rebase'
output: terminal
after:
checkForConflicts: true
- key: 'u'
context: 'global'
description: 'Update from here upward │ [rebase --upstack] Rebase upward, then push'
command: 'gh stack rebase --upstack && gh stack push'
output: terminal
after:
checkForConflicts: true
- key: 'p'
context: 'global'
description: 'Push branch updates │ [push] Push without creating or updating PRs'
command: 'gh stack push'
output: terminal
- key: 's'
context: 'global'
description: 'Create or update PRs │ [submit] Open the interactive submission editor'
command: 'gh stack submit'
output: terminal
- key: '!'
description: 'Remove stack'
commandMenu:
- key: 'l'
context: 'global'
description: 'Stop tracking locally │ [unstack --local] Keep the GitHub stack'
prompts:
- type: 'confirm'
title: 'Stop tracking this stack locally?'
body: 'The stack on GitHub will be kept.'
command: 'gh stack unstack --local'
output: terminal
- key: 'x'
context: 'global'
description: 'Remove the stack entirely │ [unstack] Unstack locally and on GitHub'
prompts:
- type: 'confirm'
title: 'Remove this stack?'
body: 'This will unstack it locally and on GitHub.'
command: 'gh stack unstack'
output: terminal
prompts:
- type: 'input'
title: 'New stack branch name'
key: 'Branch'
initialValue: '{{ runCommand "git branch --show-current | sed \"s#^stack/##\"" }}-'
command: 'gh stack add {{.Form.Branch | quote}}'
output: popup
- key: 'v'
context: 'global'
description: 'View Stack Layers │ Show all layers in the current stack'
command: 'gh stack view'
output: popup
- key: 'r'
context: 'global'
description: 'Rebase To base │ Rebase the complete stack onto master'
command: 'gh stack top && gh stack rebase'
output: terminal
- key: 'p'
context: 'global'
description: 'Update Stack from Here │ Rebase and push this layer and all above it'
command: 'gh stack rebase --upstack && gh stack push'
output: terminal
- key: 's'
context: 'global'
description: 'Submit Stack │ Create or update pull requests for the stack'
command: 'gh stack submit'
output: terminal
- key: 'm'
context: 'global'
description: 'Modify Stack │ Interactively change stack structure'
command: 'gh stack modify'
output: terminal
after:
checkForConflicts: true
- key: 'n'
description: 'Navigation'
commandMenu:
- key: 'T'
context: 'global'
description: 'Top Layer │ Switch to the highest layer'
command: 'gh stack top'
output: popup
- key: 'u'
context: 'global'
description: 'Layer Up │ Switch to the next higher layer'
command: 'gh stack up'
output: popup
- key: 'd'
context: 'global'
description: 'Layer Down │ Switch to the next lower layer'
command: 'gh stack down'
output: popup
- key: 'B'
context: 'global'
description: 'Bottom Layer │ Switch to the lowest layer'
command: 'gh stack bottom'
output: popup
- key: 'D'
context: 'global'
description: 'Layer Down with Changes │ Move uncommitted changes one layer down'
command: |
if git diff --quiet &&
git diff --cached --quiet &&
[ -z "$(git ls-files --others --exclude-standard)" ]; then
gh stack down
else
git stash push -u -m "lazygit: move changes down layer" &&
gh stack down &&
git stash pop
fi
output: popup
after:
checkForConflicts: true
- key: '!'
description: 'Danger'
commandMenu:
- key: 'x'
context: 'global'
description: 'Unstack All │ Remove stack metadata from all layers'
command: 'gh stack unstack'
output: terminal
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment