Learn how to squash, fold, and split changes with the Graphite CLI.
gt squash
allows you to squash multi-commit branches into a single commit branch, restacking upstack branches if necessary. This command is useful if you meant to run gt modify
instead of gt modify -c
, or to maintain single-commit branches after invoking gt fold
. For example:
gt fold
folds (combines) the current branch into its parent, and makes all children of the current branch children of the parent branch accordingly. It preserves the commit history of both the branches and their descendants. By default, it will use the name of the parent for the resulting combined branch, but you can use the name of the branch being folded (current branch) instead with the --keep
flag. For example:
gt split
splits the current branch into two or more branches. You can use one of two methods to split a branch:
--by-commit/--commit/-c
--by-hunk/--hunk/-h
hunk
mode automatically. If there’s more than one commit on the branch and you don’t pass in an option, you’ll be prompted to choose one.
--by-commit
flag--by-hunk
flaggit add --patch
, which prompts you to stage your changes. You can split your branch by first staging only those you’d like to include in the first branch, then giving it a name, then moving on to the second, giving that one a name, and so on.
new_feature
and I get asked to split out a necessary refactor that I included in the same branch, I can split my branch into necessary_refactor
and (a now smaller) new_feature
. When I resubmit, my feature changes will stay attached to any ongoing discussion on the original PR.