Sourced by Git's shell-script subcommands.
Internal shell setup library sourced by Git's shell-built subcommands. Provides the standard helper functions every porcelain shell script depends on.
A 'standard library' for git's .sh commands. Source it and you get say, die, cd_to_toplevel, require_work_tree, reflog action setting, GIT_DIR resolution, and all the boilerplate the C plumbing usually handles.
. "$(git --exec-path)/git-sh-setup"
# Then call helpers like:
require_work_tree
cd_to_toplevel
set_reflog_action "myscript"
say "doing the thing"
die "fatal: cannot proceed"
| Flag | What it does |
|---|---|
(sourced) say | Print to stdout unless GIT_QUIET is set |
(sourced) die | Print to stderr and exit 128 |
(sourced) cd_to_toplevel | chdir to the worktree root |
(sourced) require_work_tree | Abort if not inside a working tree |
(sourced) require_clean_work_tree | Abort on uncommitted changes (also takes 'rebase'/'merge' verb) |
(sourced) set_reflog_action | Set GIT_REFLOG_ACTION so reflog entries name your script |
(sourced) git_pager | Pipe through the configured pager |
git-foo shell extension that should feel native. "$(git --exec-path)/git-sh-setup"require_clean_work_tree rebase 'commit or stash first'cd_to_toplevelset_reflog_action 'git foo'set_reflog_action early - reflog spam without a clear actor name is a debugging nightmare.die over exit 1; it follows Git's convention of exit code 128 for fatal errors.require_work_tree does not check for index lock or repo health - just that GIT_DIR resolves to a working tree.Hit each option, then Check answers. Score is recorded; Next is always open.