Skip to content

Instantly share code, notes, and snippets.

@liggitt
Last active November 18, 2025 22:20
Show Gist options
  • Select an option

  • Save liggitt/f907dfbec31ec800e47d57fe31960884 to your computer and use it in GitHub Desktop.

Select an option

Save liggitt/f907dfbec31ec800e47d57fe31960884 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# Sample workflow for dealing with a stack of branches and associated PRs:
#
# 0. Ensure git --update-refs is enabled (only need to do this once):
# # https://andrewlock.net/working-with-stacked-branches-in-git-is-easier-with-update-refs/
# git config --global --add --bool rebase.updateRefs true
#
# 1. Make stacked branches, each with commits for logical layers of a feature
# git checkout -b myfeature-1-api-types master
# ... && git add . && git commit -m ...
# git checkout -b myfeature-2-generated-changes
# ... && git add . && git commit -m ...
# git checkout -b myfeature-3-validation
# ... && git add . && git commit -m ...
# git checkout -b myfeature-4-controller-changes
# ... && git add . && git commit -m ...
# git checkout -b myfeature-5-scheduler-changes
# ... && git add . && git commit -m ...
# git checkout -b myfeature-6-node-changes
# ... && git add . && git commit -m ...
#
# 2. git fpush-refs
# 3. Open a PR for each branch
#
# 4. Make updates in response to review comments, absorb into fixup commits for the right branches
# # https://github.com/tummychow/git-absorb
# git add ...
# git absorb --base master
# git rebase -i --autosquash master
# git fpush-refs
BASE=${BASE:-master}
REMOTE=${REMOTE:-origin}
branches=$(git for-each-ref --merged=HEAD --no-merged=${BASE} --format='%(refname:short)' refs/heads/)
echo git push --force-with-lease ${REMOTE} ${branches}
read -p "Proceed? [y/N]: " response
case "$response" in
[yY])
echo "Pushing..."
git push --force-with-lease ${REMOTE} ${branches}
;;
*)
echo "Canceling..."
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment