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 β€” and LONG_USAGE too, if you've got one β€” this is what defines the message that the usage() 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