GIT-CHECKOUT-INDEX(1)

πŸ’… git-checkout-index

okay so this is from the Git manual bestie, and it's literally the tool that copies files out of the index and into your working tree. she's niche, she's picky, and she's iconic. let's get into it 🫢


✨ NAME ✨

git-checkout-index β€” copy files from the index to the working tree πŸŽ€


✨ SYNOPSIS ✨

git checkout-index [-u] [-q] [-a] [-f] [-n] [--prefix=<string>]
                   [--stage=<number>|all]
                   [--temp]
                   [--ignore-skip-worktree-bits]
                   [-z] [--stdin]
                   [--] [<file>...]

look at her. so many little flags. she's giving ✨customizable✨ πŸ’…


✨ DESCRIPTION ✨

so what she does is: copies all the files you listed from the index into the working directory. and ngl the key thing is she does not overwrite files that already exist (unless you tell her to, more on that below πŸ‘€).


✨ OPTIONS ✨

  • -u, --index β€” updates the stat info for the entries she checked out, in the index file itself. she's keeping receipts πŸ“
  • -q, --quiet β€” be quiet if files exist or aren't in the index. no drama, no commentary πŸ’€
  • -f, --force β€” forces overwrite of existing files. she will absolutely clobber them, no cap πŸ”₯
  • -a, --all β€” checks out all the files in the index, except the ones with the skip-worktree bit set (peep --ignore-skip-worktree-bits if you wanna change that). highkey cannot be used together with explicit filenames, so pick a lane bestie βœ‹
  • -n, --no-create β€” don't check out new files, only refresh the files that are already checked out. lowkey the "touch up, don't add" mode πŸŽ€
  • --prefix=<string> β€” when creating files, prepend <string> to the name. usually that's a directory including a trailing / (the trailing slash MATTERS, remember that) πŸ¦‹
  • --stage=<number>|all β€” instead of checking out unmerged entries, copy out the files from the named stage. <number> has to be between 1 and 3 (so 1, 2, or 3, not vibes). and heads up: --stage=all automatically implies --temp 😭
  • --temp β€” instead of copying files into the working directory, she writes the content to temporary files. the temporary name associations get written to stdout. main character behavior honestly πŸ‘‘
  • --ignore-skip-worktree-bits β€” check out all the files, including the ones with the skip-worktree bit set. no skips, no exceptions ⭐
  • --stdin β€” instead of taking the path list from the command line, read the list of paths from standard input. paths are separated by LF (i.e. one path per line) by default 🌸
  • -z β€” only meaningful with --stdin. paths get separated with the NUL character instead of LF 🧚
  • -- β€” do not interpret any more arguments as options. the ultimate "everything after this is just a name, chill" move πŸ™ˆ

okay so. the order of the flags used to matter, but not anymore. glow-up πŸ’…

just doing git checkout-index does nothing. like, at all. you probably meant git checkout-index -a. and if you wanna force it, you want git checkout-index -f -a.

intuitiveness is not the goal here. repeatability is. the reason for the "no arguments means no work" behavior is that from scripts you're supposed to be able to do:

$ find . -name '*.h' -print0 | xargs -0 git checkout-index -f --

which will force all existing *.h files to be replaced with their cached copies. because think about it β€” if an empty command line implied "all", then this would force-refresh everything in the index, which was not the point at all 😀 but since git checkout-index accepts --stdin it would be faster to use:

$ find . -name '*.h' -print0 | git checkout-index -f -z --stdin

the -- is just a good idea when you know the rest will be filenames; it'll prevent problems with a filename of, for example, -a. using -- is probably a good policy in scripts. do it. i'm not asking 🫢


✨ USING --TEMP OR --STAGE=ALL ✨

when --temp is used (or implied by --stage=all) git checkout-index will create a temporary file for each index entry being checked out. the index will not be updated with stat information. these options can be useful if the caller needs all stages of all unmerged entries so that the unmerged files can be processed by an external merge tool. very "let me hand this off to someone else" of her πŸ¦‹

a listing will be written to stdout providing the association of temporary file names to tracked path names. the listing format has two variations:

  1. tempname TAB path RS

the first format is what gets used when --stage is omitted or is not --stage=all. the field tempname is the temporary file name holding the file content and path is the tracked path name in the index. only the requested entries are output.

  1. stage1temp SP stage2temp SP stage3tmp TAB path RS

the second format is what gets used when --stage=all. the three stage temporary fields (stage1temp, stage2temp, stage3temp) list the name of the temporary file if there is a stage entry in the index or . if there is no stage entry. paths which only have a stage 0 entry will always be omitted from the output.

in both formats RS (the record separator) is newline by default but will be the null byte if -z was passed on the command line. the temporary file names are always safe strings; they will never contain directory separators or whitespace characters. the path field is always relative to the current directory and the temporary file names are always relative to the top level directory ✨

if the object being copied out to a temporary file is a symbolic link the content of the link will be written to a normal file. it is up to the end-user or the Porcelain to make use of this information πŸ‘‘


✨ EXAMPLES ✨

πŸŽ€ to update and refresh only the files already checked out

$ git checkout-index -n -f -a && git update-index --ignore-missing --refresh

πŸŽ€ using git checkout-index to "export an entire tree"

the prefix ability basically makes it trivial to use git checkout-index as an "export as tree" function. just read the desired tree into the index, and do:

$ git checkout-index --prefix=git-export-dir/ -a

git checkout-index will "export" the index into the specified directory.

the final / is important. the exported name is literally just prefixed with the specified string. contrast this with the following example πŸ‘€

πŸŽ€ export files with a prefix

$ git checkout-index --prefix=.merged- Makefile

this will check out the currently cached copy of Makefile into the file .merged-Makefile. literally just glued the prefix on the front. slay 🌈


✨ GIT ✨

part of the git(1) suite πŸ’œ


and that's the whole page bestie, you ate that πŸ“ this was Git 2.56.0, dated 2026-09-27 β€” see you in the next one, mwah πŸ’‹πŸ’–

πŸ“¦ where this page comes from