GIT-SH-SETUP(1)
π GIT-SH-SETUP(1) β the git manual's sh-setup page, bestie edition π
ok so this is GIT-SH-SETUP, straight out of the git manual family. yes it's a real section 1 page. no you will not be running it. let's go π
β¨ NAME β¨
git-sh-setup β the common Git shell script setup code, aka the little helper blob that makes other Git shell scripts not have to reinvent the wheel π
πΈ SYNOPSIS πΈ
. "$(git --exec-path)/git-sh-setup"
note the leading dot, bestie β that's source, and it matters. do not just run this thing. literally do not π«Ά
π DESCRIPTION π
okay first things first, and I need you to hear me: this is not a command the end user would want to run. Ever. like, ever ever. not even out of curiosity. not even on a dare. this documentation exists for the study girlies β the people reading through the Porcelain-ish scripts, and/or the people writing brand new ones. iykyk β¨
the git sh-setup scriptlet is designed to be sourced (using ., remember?) by other shell scripts. what it does is set up some variables that point at the normal Git directories, plus a handful of helper shell functions so your script gets to freeload off all that β¨
before you source it, your script should set up a few variables of its own:
USAGEβ andLONG_USAGEtoo, if you've got one β this is what defines the message that theusage()shell function prints out π£οΈSUBDIRECTORY_OKβ you can set this if your script is allowed to run from a subdirectory of the working tree. important caveat: some commands do not, so don't just set it because it looks cute π
and one more thing to know: the scriptlet sets the GIT_DIR and GIT_OBJECT_DIRECTORY shell variables, but it does not export them to the environment. so they're yours, in your shell, and they stay there. no cap.
π₯ FUNCTIONS π₯
die
exits, but first it emits the error message you supplied to the standard error stream. dramatic exit, but make it informative π
usage
die, but with the usage message. so it's the "you're holding it wrong" exit π
set_reflog_action
sets the GIT_REFLOG_ACTION environment variable to a given string β typically the name of the program β unless it is already set (so it won't stomp on an existing value, respectful queen π).
the point of this: whenever the script runs a git command that updates refs, a reflog entry gets created using the value of this string, so the reflog leaves a record of what command updated the ref. it's literally leaving receipts, and honestly? iconic π
git_editor
runs an editor of the user's choice on a given file β checking GIT_EDITOR, core.editor, VISUAL or EDITOR β but it will error out if no editor is specified and the terminal is dumb. like, it's not gonna try to open vim into the void for you. it's got standards π§
is_bare_repository
outputs true or false to the standard output stream, telling you whether the repository is a bare repository (i.e. one with no associated working tree). a simple yes/no vibe check π¦
cd_to_toplevel
runs chdir to the toplevel of the working tree. congrats, you're at the top now, enjoy the view β
require_work_tree
checks if the current directory is within the working tree of the repository, and otherwise dies. no working tree? no service. periodt π
require_work_tree_exists
checks if the working tree associated with the repository exists, and otherwise dies. this one is often done before calling cd_to_toplevel β which is, and I cannot stress this enough, impossible to do if there is no working tree. you cannot chdir to a place that isn't there, bestie π
require_clean_work_tree <action> [<hint>]
checks that the working tree and the index associated with the repository have no uncommitted changes to tracked files. otherwise it emits an error message of the form:
Cannot <action>: <reason>. <hint>
β¦and then it dies. π
example, because examples slay:
require_clean_work_tree rebase "Please commit or stash them."
get_author_ident_from_commit
outputs code for use with eval to set the GIT_AUTHOR_NAME, GIT_AUTHOR_EMAIL and GIT_AUTHOR_DATE variables for a given commit. three variables, one commit, zero mess β¨
create_virtual_base
modifies the first file so that only the lines in common with the second file remain. if there's insufficient common material, then the first file is left empty. the result is suitable as a virtual base input for a 3-way merge β which, yes, is exactly as cool as it sounds π
π GIT π
part of the git(1) suite π
and that's the whole page, bestie β you ate that reading ngl π this was GIT-SH-SETUP(1) from Git 2.56.0, dated 2026-09-27. go forth and source responsibly π«Άπ
π¦ where this page comes from
- arch rolling: git 2.56.0-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