STG(1)
π STG(1) β Manage stacks of patches using the Git content tracker π
okay bestie, welcome to the StGit Manual β this is the page for stg, and weβre gonna make it make sense. No cap.
π NAME π
stg β Manage stacks of patches using the Git content tracker
β¨ SYNOPSIS β¨
stg [OPTIONS] <command> [...]
stg [OPTIONS] <-h|--help>
stg --version
π¦ DESCRIPTION π¦
StGit (Stacked Git) is an application that provides a convenient way to maintain a patch stack on top of a Git branch:
- The topmost (most recent) commits of a branch are given names. Such a named commit is called a patch.
- After making changes to the worktree, you can incorporate the changes into an existing patch; this is called refreshing. You may refresh any patch, not just the topmost one.
- You can pop a patch: temporarily putting it aside, so that the patch below it becomes the topmost patch. Later you may push it onto the stack again. Pushing and popping can be used to reorder patches.
- You can easily rebase your patch stack on top of any other Git commit. (The base of a patch stack is the most recent Git commit that is not an StGit patch.) For example, if you started making patches on top of someone elseβs branch, and that person publishes an updated branch, you can take all your patches and apply them on top of the updated branch.
- As you would expect, changing what is below a patch can cause that patch to no longer apply cleanly β this can occur when you reorder patches, rebase patches, or refresh a non-topmost patch. StGit uses Gitβs rename-aware three-way merge capability to automatically fix up what it can; if it still fails, it lets you manually resolve the conflict just like you would resolve a merge conflict in Git.
- The patch stack is just some extra metadata attached to regular Git commits, so you can continue to use most Git tools along with StGit.
πΈ Typical uses πΈ
π Tracking branch
Tracking changes from a remote branch, while maintaining local modifications against that branch, possibly with the intent of sending some patches upstream. You can modify your patch stack as much as you want, and when your patches are finally accepted upstream, the permanent recorded Git history will contain just the final sequence of patches, and not the messy sequence of edits that produced them.
Commands of interest in this workflow are e.g. rebase and mail.
π Development branch
Even if you have no "upstream" to send patches to, you can use StGit as a convenient way to modify the recent history of a Git branch. For example, instead of first committing change A, then change B, and then A2 to fix A because it wasnβt quite right, you could incorporate the fix directly into A. This way of working results in a much more readable Git history than if you had immortalized every misstep you made on your way to the right solution.
Commands of interest in this workflow are e.g. uncommit, which can be used to move the patch stack base downwards β i.e., turn Git commits into StGit patches after the fact β and commit, its inverse.
For more information, see the tutorial[1].
π¦ Specifying patches π¦
Most StGit commands have patch arguments. Patches in the stack may be specified in a variety of ways. A patch in the current branch may simply be referred to by its name, or, alternatively, be located by a relative offset from the topmost patch (e.g. +3), as an absolute index into the stack (e.g. 7), or as an offset from the last visible patch (e.g. ^1).
Some commands allow you to specify a patch in another branch of the repository; this is done by prefixing the patch name with the branch name and a colon (e.g. otherbranch:thatpatch).
Commands that take multiple patch arguments may be supplied with patch ranges of the form patch1..patchN as an alternative to specifying each patch individually. For example, stg delete p0..p4 would be equivalent to stg delete p0 p1 p2 p3 p4. Patch ranges may be open on either or both ends. For example, stg delete ..p2 would delete the first applied patch up to and including patch p2. Alternatively, stg delete p2.. would delete patch p2 up to and including the topmost applied patch. And stg delete .. would delete all applied patches.
The complete syntax for locating patches follows:
<patchname>, e.g.patchβ The name of a patch.@β Refers to the topmost applied patch, or the base of the stack if no patches are applied.[<patchname>]~[<n>], e.g.~2,patch~,patch~3β The<n>th previous patch from the named patch. If<patchname>is not supplied,@is implied. A single~represents the first previous patch. Multiple~may be specified, e.g.patch~~~is the same aspatch~3. This is similar to gitβs revision syntax where<rev>~[<n>]means the<n>th ancestor commit from<rev>following first parents.[<patchname>]+[<n>], e.g.+,+3,patch+,patch+3β The<n>th next patch from the named patch. If<patchname>is not supplied,@is implied. A single+represents the next patch in the series. Multiple+may be specified, e.g.patch+++is the same aspatch+3.-[<n>], e.g.-3,-β References the<n>th previously applied patch. This is similar to~<n>, except it is only valid without a patch name prefix. Note that certain commands with other options taking numeric values may require escaping-with\-, e.g.\-10.<n>, e.g.3β The patch at absolute index<n>in the stack. This is a zero-based index, so0refers to the bottommost patch in the stack.^[<n>], e.g.^,^3β The patch at offset<n>from the last visible patch in the stack. This is a zero-based offset, so^0refers to the last visible patch in the stack, which is equivalent to just^. Negative values of<n>are allowed and refer to hidden patches which are after the last visible patch in the stack.{base}+[<n>], e.g.{base}+,{base}+3β The patch at offset<n>from the stackβs base commit. Since the stack base is not a commit, a positive offset is required.
Take note that numeric patch locations of the form <n>, -<n>, and +<n>, e.g. 3, -3, or +3 are also valid patch names. I.e. it is possible (but not recommended) to name a patch, for example, "-3". In the case where a patch name could also be interpreted as a numeric index or offset, the literal patch name will take precedence when resolving the patch location.
π Specifying commits π
Some StGit commands take Git commits as arguments. StGit accepts all revision specifications that Git does (see gitrevisions(7)); and additionally, the patch specifiers from above. The usual Git modifiers, including ^, are also allowed; e.g. some-branch:a-patch^^ refers to the grandparent of the commit that is patch a-patch on branch some-branch.
If you need to pass a given StGit reference to a Git command, stg-id(1) will convert it to a Git commit id for you.
π OPTIONS π
The following generic option flags are available. Additional options are available for (and documented with) the different subcommands.
--versionβ Print version information--helpβ Print help information.-Cβ Run as ifstgwas started in<path>instead of the current working directory. When multiple-Coptions are given, each subsequent non-absolute-C <path>is interpreted relative to the preceding-C <path>.
This option affects arguments that expect path names or path specs in that their interpretations of the path names would be made relative to the working directory caused by the -C option.
--color <when>β Specify when to colorize the output.
auto (the default) enables colored output only when outputting to a terminal or TTY. The NO_COLOR environment variable is respected.
always and never unconditionally enable/disable colored output, respectively.
ansi forces color to be output using ANSI escape sequences, even in a Windows console.
π οΈ STGIT COMMANDS π οΈ
okay so real talk: StGit has a lot of commands, and we sort them into thematic little cliques based on the primary type of object they create or change. it's giving organized. it's giving β¨taxonomyβ¨.
here's the quick rundown of every single one. want the full tea on any of them? each command has its own manpage with all the details β those are named stg-<command>(1). cute, right? π
π Patch Inspection π
the read-only girlies. they just look at stuff and report back. no notes. π
stg-diff(1)β show you a diffstg-files(1)β show you which files a patch modifiedstg-id(1)β print the git hash of a StGit revisionstg-log(1)β display the stack changelog, or optionally clear it if that's the vibestg-name(1)β print the patch name of a StGit revisionstg-show(1)β show the patch commits
π¨ Patch Manipulation π¨
this is where you actually do things to patches. main character energy fr fr.
stg-edit(1)β edit a patchstg-fold(1)β fold a diff file into the current patchstg-new(1)β create a new patch at the top of the stackstg-refresh(1)β incorporate worktree changes into the current patchstg-rename(1)β rename a patchstg-spill(1)β spill changes out of the topmost patchstg-sync(1)β synchronize patches with a branch or a series
π Stack Inspection π
again with the looking, but now it's the whole stack bestie. very demure, very observant. π¦
stg-email(1)β format and send patches as emailstg-export(1)β export patches to a directorystg-next(1)β print the name of the next patchstg-patches(1)β show the patches that modify given filesstg-prev(1)β print the name of the previous patchstg-series(1)β display the patch seriesstg-top(1)β print the name of the top patch
π₯ Stack Manipulation π₯
the heavy hitters. this is the section that ate and left no crumbs. π
stg-branch(1)β branch operations: switch, list, create, rename, delete, ...stg-clean(1)β delete empty patches from the seriesstg-commit(1)β finalize patches to the stack basestg-delete(1)β delete patchesstg-float(1)β push patches to the top, even if appliedstg-goto(1)β go to a patch by pushing or popping as necessarystg-hide(1)β hide patches in the seriesstg-import(1)β import patches to the stackstg-init(1)β initialize a StGit stack on a branchstg-pick(1)β import a patch from another branch or a commit objectstg-pop(1)β pop (unapply) one or more applied patchesstg-pull(1)β pull changes from a remote repositorystg-push(1)β push (apply) one or more unapplied patchesstg-rebase(1)β move the stack base to another point in historystg-redo(1)β undo the last undo operation (yes really, we said what we said π)stg-repair(1)β repair the stack after the branch was modified with git commandsstg-reset(1)β reset the patch stack to an earlier statestg-sink(1)β move patches deeper in the stackstg-squash(1)β squash two or more patches into onestg-uncommit(1)β convert regular Git commits into StGit patchesstg-undo(1)β undo the last commandstg-unhide(1)β unhide hidden patches
π§ Administration π§
the backstage crew keeping the whole production running. lowkey iconic. π
stg-completion(1)β support for shell completionsstg-help(1)β print this message or the help of the given subcommand(s)stg-version(1)β print version information and exit π
βοΈ CONFIGURATION MECHANISM βοΈ
Okay bestie, here's the tea: StGit doesn't reinvent the wheel when it comes to config β it uses the exact same configuration mechanism as Git. So all your Git config muscle memory? Slay, it just works. Peep git-config(1) for the full deets. π
π Variables π
branch.<name>.stgit.autostash,branch.<name>.stgit.fetchcmd,branch.<name>.stgit.pull-policy,branch.<name>.stgit.pullcmd,branch.<name>.stgit.rebasecmdβ these are the branch-specific versions of the config values, and they take precedence over the corresponding non-branch specific ones (scroll down, they're all listed below π).branch.<name>.stgit.parentbranchβ tells you the parent branch of a branch that's got a StGit stack. Heads up: this one is set bystg-branch(1)when you create or clone branches, and it's not typically set by the user. Where it matters:stg-pull(1)reads it whenstgit.pull-policyis eitherrebaseorfetch-rebase, so it can figure out the target of the rebase. π―stgit.alias.*β command aliases forstg, periodt. So like, after you definestgit.alias.list = series -d, runningstg listis literally equivalent tostg series -d. Arguments get split by spaces, and the usual shell quoting and escaping is supported β a quote pair or a backslash may be used to quote them.
And here's the iconic part: if the alias expansion is prefixed with an exclamation point (!), it gets treated as a shell command. Example: defining stgit.alias.outgoing = !git log @{u} means running stg outgoing is equivalent to running the shell command git log @{u}. Note that shell commands will be executed from the top-level directory of the working tree, which may not necessarily be the current directory. GIT_PREFIX is set as returned by running git rev-parse --show-prefix from the original current directory. See git-rev-parse(1). π
Aliases that would hide existing StGit commands are ignored. π
stgit.autoimergeβ set it totrueand if conflicts pop off when pushing a patch,git-mergetool(1)gets automatically run to attempt to resolve them. Auto-rescue mode activated. π¦ΈββοΈstgit.autosignβ automatically adds a signoff trailer to commit messages for new patches created withstg-new(1)orstg-import(1). Here's the trick: the value of this config variable is used as the key of the trailer, so it should be set to something likeSigned-off-by. π«stgit.autostashβ when runningstg-rebase(1), if any modified files are found in the working tree, a temporary stash is created withgit-stash(1)before the operation begins, and it gets applied after the operation completes. Your uncommitted work said "not today" and got tucked away safely. π§Ίstgit.diff-optsβ options passed through togit diff-treeforstg-diff(1),stg-export(1),stg-patches(1), andstg-show(1). You can specify multiple space-separated options. Seegit-diff-tree(1)for info about the various available options. β¨stgit.edit.verboseβ set totrueand the patch's diff gets shown when you're interactively editing a patch description with, for example,stg-edit(1). Context is giving main character energy. πstgit.editorβ commands likestg-edit(1)andstg-new(1)open an editor to edit the patch description and commit message. The editor set by this variable is launched when theGIT_EDITORenvironment variable is not set. And get this: this variable takes precedence over thecore.editorconfiguration variable as well as theVISUALandEDITORenvironment variables. It's the top of the editor food chain, fr fr. π§stgit.fetchcmdβ the command specified here gets run bystg-pull(1)to fetch from the remote repository whenstgit.pull-policyisfetch-rebase. When it's not set, the default command isgit fetch. π‘stgit.gpgsignβ a boolean specifying whether StGit stack metadata commits should be GPG signed.
N.B. Setcommit.gpgsignto determine whether patch commits themselves are GPG signed. Seegit-config(1)for more information aboutcommit.gpgsign. π
stgit.import.message-idβ set totrueand it creates aMessage-ID:trailer in the patch description of patches imported from email usingstg-import(1). π¬stgit.infer-commandsβ when set totrue, StGit commands and aliases may be invoked using any unambiguous prefix of their names. Example incoming:stg serrunsstg series. Exact command and alias names always take precedence over prefixes. Prefixes are not accepted in alias definitions β aliases must name their StGit command exactly. Defaults tofalse. π§
N.B. whether a prefix is unambiguous depends on the set of defined aliases as well as the set of StGit commands. Defining a new alias, or upgrading to a version of StGit with new commands, may cause a previously unambiguous prefix to become ambiguous. Explicit aliases (see stgit.alias.*) are a more stable alternative for abbreviating commonly used commands. β οΈ
stgit.keepoptimizedβ set totrueand, after pulling changes withstg-pull(1), the repository's object database will be optimized by runninggit-repack(1). Glow-up for your object database. π₯stgit.namelengthβ an integer used to determine the maximum length, in characters, of automatically generated patch names. The default value is30. This option does not affect user-specified patch names. Setting it to a value less than or equal to0will allow automatically generated patch names of unlimited length. π
Automatically generated patch names are truncated at word boundaries less than or equal to the value of stgit.namelength. As a result, patch names will typically not be truncated at exactly this number of characters. It's also possible for automatically generated patch names to be longer than this value if a work boundary cannot be found within this bound, or if additional characters need to be added to the patch name to make it unique. So like, it's a vibe guideline, not a hard wall. π
stgit.pick.expose-formatβ the format of the commit message for patches picked using the--exposeoption withstg-pick(1). The value of this option is as may be specified to the--prettyoption ofgit-show(1). The default isformat:%B%n(imported from commit %H). πstgit.pull-policyβ the policy used bystg-pull(1)for pulling changes from a remote repository. Valid values include:pullβ the default β usesgit-pull(1)orstgit.pullcmd, if set, to pull changes from the remote repository.rebaseβ usesgit-reset(1)orstgit.rebasecmd, if set, to rebase the patch stack before reapplying patches.fetch-rebaseβ first fetches commits from the remote repository usinggit-fetch(1)orstgit.fetchcmd, if set, before performing the rebase as described above.
stgit.pullcmdβ the command to be run bystg-pull(1)to pull changes from the remote repository whenstgit.pull-policyispull(the default). The default value isgit pull. πstgit.push.allow-conflictsβ a boolean specifying whetherstg-push(1)and other commands that push patches will push patches that may result in merge conflicts. The default istrue, which means a patch with conflicts will be pushed, and if the conflicts can't be automatically resolved, the operation will stop with the conflicts left to be resolved manually. π
When set to false, a patch that would have merge conflicts will not be pushed, thus leaving the stack on the last patch that could be pushed without conflicts.
This configuration variable may be overridden on the command line with either --conflicts[=allow] or --conflicts=disallow. π«Ά
N.B.: stgit.autoimerge only has an affect when push conflicts are allowed. π
stgit.rebasecmdβ the command to be run bystg-pull(1)to set the new stack base whenstgit.pull-policyis eitherrebaseorfetch-rebase. The default isgit reset --hard. πͺstgit.refreshsubmodulesβ a boolean specifying whetherstg-refresh(1)includes submodules in patch content. This value may be overridden by the--submodulesor--no-submodulesoption tostg-refresh(1). By default, submodule content is not included in patch content. π§©stgit.shortnrβ the number of patches listed bystg-series(1)when the-s/--shortoption is specified. Defaults to5. β
π TEMPLATES π
A bunch of StGit commands make use of template files to hand you useful default texts that you then get to edit. These <name>.tmpl template files get searched in the following directories, in this order:
$GITDIR/(in practice, the.git/directory in your repository)$XDG_CONFIG_HOME/stgit/templates/$HOME/.stgit/templates/
First one wins, so put your personal templates where they belong bestie. πΈ
π NOTES π
- tutorial β
https://stacked-git.github.io/guides/tutorial
And that's the whole page, bestie!! π¦ You just read the entire STG(1) manpage and honestly? Iconic behavior. This beauty is StGit 2.7.0, dated 10/17/2026 β go forth and stack those patches, you absolute legend. πβ¨π
π¦ where this page comes from
- opensuse-leap 16.0: stgit 2.7.0-bp160.1.1 Β· GPL-2.0-only
- opensuse-leap 16.0: stgit 2.7.0-bp160.1.1 Β· GPL-2.0-only
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms