GIT-UPDATE-INDEX(1)
π GIT-UPDATE-INDEX(1) β the git-update-index glow-up π
okay so bestie. this is the git-update-index(1) manual page, and yes it's from the Git Manual, and yes it's a lot. but like β it's giving foundational. it's the thing that literally puts your file contents from the working tree into the index. iconic behavior. let's get into it π¦
β¨ NAME β¨
git-update-index β register file contents in the working tree to the index
πΈ SYNOPSIS πΈ
git update-index
[--add] [--remove | --force-remove] [--replace]
[--refresh] [-q] [--unmerged] [--ignore-missing]
[(--cacheinfo <mode>,<object>,<file>)...]
[--chmod=(+|-)x]
[--[no-]assume-unchanged]
[--[no-]skip-worktree]
[--[no-]ignore-skip-worktree-entries]
[--[no-]fsmonitor-valid]
[--ignore-submodules]
[--[no-]split-index]
[--[no-|test-|force-]untracked-cache]
[--[no-]fsmonitor]
[--really-refresh] [--unresolve] [--again | -g]
[--info-only] [--index-info]
[-z] [--stdin] [--index-version <n>]
[--show-index-version]
[--verbose]
[--] [<file>...]
π DESCRIPTION π
So what this command does is it modifies the index. Every file you mention gets updated into the index, and any unmerged or needs updating state gets cleared. clean slate energy β¨
Also, heads up: if you want a more user-friendly way to do the most common index operations, peep git-add(1) β that's the main character for everyday stuff. git update-index is more the backstage icon that makes it all happen π
The way git update-index handles the files it's told about can be modified using the various options β and bestie, there are so many options. let's go π
π OPTIONS π
--addβ if a file you specified isn't in the index already, it gets added. the default behavior is to ignore new files, so if your new file is being ghosted, this is your girl.--removeβ if a file you specified is in the index but it's missing, it gets removed. default behavior is to ignore removed files, fr fr.--refreshβ looks at the current index and checks whether merges or updates are needed by checkingstat()information. it's the vibe check for your stat data π-qβ quiet mode. so normally, if--refreshfinds that the index needs an update, the default behavior is to error out. this option makesgit update-indexcontinue anyway. no drama, just vibes.--ignore-submodulesβ do not try to update submodules. π« tiny detail but important: this option is only respected when passed before--refresh.--unmergedβ if--refreshfinds unmerged changes in the index, the default behavior is to error out. this option makesgit update-indexcontinue anyway. again: no drama π--ignore-missingβ ignores missing files during a--refresh.--cacheinfo <mode>,<object>,<path>,--cacheinfo <mode> <object> <path>β directly insert the specified info into the index. for backward compatibility you can also give these three arguments as three separate parameters, but new users are encouraged to use a single-parameter form (the comma version, bestie β it's cleaner).--index-infoβ read index information from stdin.--chmod=(+|-)xβ set the execute permissions on the updated files. little+x/-xmoment π--assume-unchanged,--no-assume-unchangedβ when this flag is specified, the object names recorded for the paths are not updated. instead, this option sets/unsets the "assume unchanged" bit for the paths. when the "assume unchanged" bit is on, the user promises not to change the file and allows Git to assume that the working tree file matches what is recorded in the index. if you do want to change the working tree file, you need to unset the bit to tell Git. this is sometimes helpful when working with a big project on a filesystem that has a very slowlstat(2)system call (e.g.cifs).
β οΈ okay important one: Git will fail (gracefully) in case it needs to modify this file in the index, e.g. when merging in a commit. so in case the assumed-untracked file is changed upstream, you will need to handle the situation manually. no cap, it's on you.
--really-refreshβ like--refresh, but checks stat information unconditionally, without regard to the "assume unchanged" setting. it does not play about that bit π₯--skip-worktree,--no-skip-worktreeβ when one of these flags is specified, the object names recorded for the paths are not updated. instead, these options set and unset the "skip-worktree" bit for the paths. see the section "Skip-worktree bit" below for more info (it's later in the page, iykyk).--ignore-skip-worktree-entries,--no-ignore-skip-worktree-entriesβ do not remove skip-worktree (AKA "index-only") entries even when the--removeoption was specified. protect the girlies π«Ά--fsmonitor-valid,--no-fsmonitor-validβ when one of these flags is specified, the object names recorded for the paths are not updated. instead, these options set and unset the "fsmonitor valid" bit for the paths. see the section "File System Monitor" below for more.-g,--againβ runsgit update-indexitself on the paths whose index entries are different from those of theHEADcommit. it's like a do-over but make it efficient β¨--unresolveβ restores the unmerged or needs updating state of a file during a merge if it was cleared by accident. undo button for a merge oopsie π--info-onlyβ do not create objects in the object database for all<file>arguments that follow this flag; just insert their object IDs into the index. object database stays untouched, periodt.--force-removeβ remove the file from the index even when the working directory still has such a file. (implies--remove.) like, yes it's still there, and no, we don't care π--replaceβ by default, when a filepathexists in the index,git update-indexrefuses an attempt to addpath/file. similarly if a filepath/fileexists, a filepathcannot be added. with the--replaceflag, existing entries that conflict with the entry being added are automatically removed with warning messages. conflict resolution but make it loud π--stdinβ instead of taking a list of paths from the command line, read a list of paths from the standard input. paths are separated by LF (i.e. one path per line) by default.--verboseβ report what is being added and removed from the index. we love receipts π--index-version <n>β write the resulting index out in the named on-disk format version. supported versions are2,3, and4. the current default version is2or3, depending on whether extra features are used, such asgit add -N. with--verbose, also report the version the index file uses before and after this command.
Version 4 performs a simple pathname compression that reduces index size by 30%-50% on large repositories, which results in faster load time. Git supports it since version 1.8.0, released in October 2012, and support for it was added to libgit2 in 2016 and to JGit in 2020. older versions of this manual page called it "relatively young", but it should be considered mature technology these days. she grew up π
--show-index-versionβ report the index format version used by the on-disk index file. see--index-versionabove.-zβ only meaningful with--stdinor--index-info; paths are separated with NUL character instead of LF. tiny flag, big difference.--split-index,--no-split-indexβ enable or disable split index mode. if split-index mode is already enabled and--split-indexis given again, all changes in$GIT_DIR/indexare pushed back to the shared index file.
These options take effect whatever the value of the core.splitIndex configuration variable (see git-config(1)). But a warning is emitted when the change goes against the configured value, as the configured value will take effect next time the index is read and this will remove the intended effect of the option. so like, the config comes back for round two π
--untracked-cache,--no-untracked-cacheβ enable or disable untracked cache feature. please use--test-untracked-cachebefore enabling it. (this is not a drill, test first bestie.)
These options take effect whatever the value of the core.untrackedCache configuration variable (see git-config(1)). But a warning is emitted when the change goes against the configured value, as the configured value will take effect next time the index is read and this will remove the intended effect of the option.
--test-untracked-cacheβ only perform tests on the working directory to make sure untracked cache can be used. you have to manually enable untracked cache using--untracked-cacheor--force-untracked-cacheor thecore.untrackedCacheconfiguration variable afterwards if you really want to use it. if a test fails the exit code is1and a message explains what is not working as needed; otherwise the exit code is0andOKis printed. it's giving pass/fail exam π--force-untracked-cacheβ same as--untracked-cache. provided for backwards compatibility with older versions of Git where--untracked-cacheused to imply--test-untracked-cachebut this option would enable the extension unconditionally.--fsmonitor,--no-fsmonitorβ enable or disable files system monitor feature. these options take effect whatever the value of thecore.fsmonitorconfiguration variable (seegit-config(1)). But a warning is emitted when the change goes against the configured value, as the configured value will take effect next time the index is read and this will remove the intended effect of the option. yes, it's the same warning as before. the config is committed to its choices π--β do not interpret any more arguments as options. everything after this is just a file, babe. the end of options energy π<file>β files to act on. note that files beginning with.are discarded. this includes./fileanddir/./file. if you don't want this, then use cleaner names. the same applies to directories ending/and paths with//. so likeβ¦ naming matters, bestie π
π¦ USING --REFRESH π¦
Okay so real talk: --refresh does not calculate a new sha1 file or bring the index up to date for mode/content changes. nope. what it does do is "re-match" the stat information of a file with the index, so that you can refresh the index for a file that hasn't been changed but where the stat entry is out of date.
For example, you'd want to do this after doing a git read-tree, to link up the stat index details with the proper files. it's literally just syncing the vibes between your stat info and your files β¨
π§ USING --CACHEINFO OR --INFO-ONLY π§
--cacheinfo is used to register a file that is not in the current working directory. this is useful for minimum-checkout merging.
To pretend you have a file at path with mode and sha1, say:
$ git update-index --add --cacheinfo <mode>,<sha1>,<path>
--info-only is used to register files without placing them in the object database. this is useful for status-only repositories.
Both --cacheinfo and --info-only behave similarly: the index is updated but the object database isn't. --cacheinfo is useful when the object is in the database but the file isn't available locally. --info-only is useful when the file is available, but you do not wish to update the object database. see how they're like sisters with different priorities π
β¦and that's literally just part one, bestie. there's more where this came from ππ
β¨ USING --INDEX-INFO β¨
okay so --index-info is the more powerful one, bestie. it lets you feed multiple entry definitions from standard input, and itβs designed specifically for scripts. it can take inputs in three formats:
mode SP type SP sha1 TAB paththis format is for stuffinggit ls-treeoutput into the index. iconic.mode SP sha1 SP stage TAB paththis one puts higher order stages into the index file and matchesgit ls-files --stageoutput. slay.mode SP sha1 TAB pathno Git command produces this format anymore, but it is and will continue to be supported byupdate-index --index-info. periodt.
to place a higher stage entry into the index, the path should first be removed by feeding a mode=0 entry for the path, and then feeding the necessary input lines in the third format. yes, thatβs the move.
for example, starting with this index:
$ git ls-files -s
100644 8a1218a1024a212bb3db30becd860315f9f3ac52 0 frotz
you can feed the following input to --index-info:
$ git update-index --index-info
0 0000000000000000000000000000000000000000 frotz
100644 8a1218a1024a212bb3db30becd860315f9f3ac52 1 frotz
100755 8a1218a1024a212bb3db30becd860315f9f3ac52 2 frotz
the first line of the input feeds 0 as the mode to remove the path; the SHA-1 does not matter as long as it is well formatted. then the second and third lines feed stage 1 and stage 2 entries for that path. after the above, we would end up with this:
$ git ls-files -s
100644 8a1218a1024a212bb3db30becd860315f9f3ac52 1 frotz
100755 8a1218a1024a212bb3db30becd860315f9f3ac52 2 frotz
β¨ USING βASSUME UNCHANGEDβ BIT β¨
many operations in Git depend on your filesystem having an efficient lstat(2) implementation, so that st_mtime information for working tree files can be cheaply checked to see if the file contents have changed from the version recorded in the index file. unfortunately, some filesystems have inefficient lstat(2). if your filesystem is one of them, you can set the "assume unchanged" bit to paths you have not changed to cause Git not to do this check. note that setting this bit on a path does not mean Git will check the contents of the file to see if it has changed β it makes Git omit any checking and assume it has not changed. when you make changes to working tree files, you have to explicitly tell Git about it by dropping the "assume unchanged" bit, either before or after you modify them. no cap, that part matters.
in order to set the "assume unchanged" bit, use --assume-unchanged. to unset it, use --no-assume-unchanged. to see which files have the "assume unchanged" bit set, use git ls-files -v (see git-ls-files(1)). cute and useful.
the command looks at the core.ignorestat configuration variable. when this is true, paths updated with git update-index paths... and paths updated with other Git commands that update both index and working tree (e.g. git apply --index, git checkout-index -u, and git read-tree -u) are automatically marked as "assume unchanged". note that the "assume unchanged" bit is not set if git update-index --refresh finds the working tree file matches the index (use git update-index --really-refresh if you want to mark them as "assume unchanged"). okay so thatβs the little twist.
sometimes users confuse the assume-unchanged bit with the skip-worktree bit. see the final paragraph in the "Skip-worktree bit" section below for an explanation of the differences. literally keep reading, bestie.
π EXAMPLES π
to update and refresh only the files already checked out:
$ git checkout-index -n -f -a && git update-index --ignore-missing --refresh
on an inefficient filesystem with core.ignorestat set:
$ git update-index --really-refresh (1)
$ git update-index --no-assume-unchanged foo.c (2)
$ git diff --name-only (3)
$ edit foo.c
$ git diff --name-only (4)
M foo.c
$ git update-index foo.c (5)
$ git diff --name-only (6)
$ edit foo.c
$ git diff --name-only (7)
$ git update-index --no-assume-unchanged foo.c (8)
$ git diff --name-only (9)
M foo.c
- forces
lstat(2)to set "assume unchanged" bits for paths that match the index. - mark the path to be edited.
- this does
lstat(2)and finds the index matches the path. - this does
lstat(2)and finds the index does not match the path. - registering the new version to the index sets the "assume unchanged" bit.
- and it is assumed unchanged.
- even after you edit it. yes, really.
- you can tell about the change after the fact.
- now it checks with
lstat(2)and finds it has been changed.
π¦ SKIP-WORKTREE BIT π¦
the skip-worktree bit can be defined in one long sentence: tell Git to avoid writing the file to the working directory when reasonably possible, and treat the file as unchanged when it is not present in the working directory. thatβs the whole vibe.
note that not all Git commands will pay attention to this bit, and some only partially support it. rude but true.
the update-index flags and the read-tree capabilities relating to the skip-worktree bit predated the introduction of the git-sparse-checkout(1) command, which provides a much easier way to configure and handle the skip-worktree bits. if you want to reduce your working tree to only deal with a subset of the files in the repository, we strongly encourage the use of git-sparse-checkout(1) in preference to the low-level update-index and read-tree primitives. bestie, take the easy road.
the primary purpose of the skip-worktree bit is to enable sparse checkouts, i.e. to have working directories with only a subset of paths present. when the skip-worktree bit is set, Git commands (such as switch, pull, merge) will avoid writing these files. however, these commands will sometimes write these files anyway in important cases such as conflicts during a merge or rebase. Git commands will also avoid treating the lack of such files as an intentional deletion; for example git add -u will not stage a deletion for these files and git commit -a will not make a commit deleting them either. good, because that would be chaos.
although this bit looks similar to the assume-unchanged bit, its goal is different. the assume-unchanged bit is for leaving the file in the working tree but having Git omit checking it for changes and presuming that the file has not been changed (though if it can determine without statβing the file that it has changed, it is free to record the changes). skip-worktree tells Git to ignore the absence of the file, avoid updating it when possible with commands that normally update much of the working directory (e.g. checkout, switch, pull, etc.), and not have its absence be recorded in commits. note that in sparse checkouts (setup by git sparse-checkout or by configuring core.sparseCheckout to true), if a file is marked as skip-worktree in the index but is found in the working tree, Git will clear the skip-worktree bit for that file. so yeah, thatβs the difference, iykyk.
π SPLIT INDEX π
this mode is designed for repositories with very large indexes, and aims at reducing the time it takes to repeatedly write these indexes. big repo energy.
in this mode, the index is split into two files: $GIT_DIR/index and $GIT_DIR/sharedindex.<SHA-1>. changes are accumulated in $GIT_DIR/index, the split index, while the shared index file contains all index entries and stays unchanged. literally the whole point.
all changes in the split index are pushed back to the shared index file when the number of entries in the split index reaches a level specified by the splitIndex.maxPercentChange config variable (see git-config(1)). noted.
each time a new shared index file is created, the old shared index files are deleted if their modification time is older than what is specified by the splitIndex.sharedIndexExpire config variable (see git-config(1)). okay, cleanup time.
to avoid deleting a shared index file that is still used, its modification time is updated to the current time every time a new split index based on the shared index file is either created or read from. protective and iconic.
π UNTRACKED CACHE π
this cache is meant to speed up commands that involve determining untracked files, such as git status. we love a fast status.
this feature works by recording the mtime of the working tree directories and then omitting reading directories and stat calls against files in those directories whose mtime hasnβt changed. for this to work, the underlying operating system and file system must change the st_mtime field of directories if files in the directory are added, modified or deleted. thatβs the whole requirement, bestie.
you can test whether the filesystem supports that with the --test-untracked-cache option. the --untracked-cache option used to implicitly perform that test in older versions of Git, but thatβs no longer the case. okay so donβt assume, test it.
if you want to enable (or disable) this feature, it is easier to use the core.untrackedCache configuration variable (see git-config(1)) than using the --untracked-cache option to git update-index in each repository, especially if you want to do so across all repositories you use, because you can set the configuration variable to true (or false) in your $HOME/.gitconfig just once and have it affect all repositories you touch. set it once, slay everywhere.
when the core.untrackedCache configuration variable is changed, the untracked cache is added to or removed from the index the next time a command reads the index; while when --[no-|force-]untracked-cache are used, the untracked cache is immediately added to or removed from the index. subtle but important.
before 2.17, the untracked cache had a bug where replacing a directory with a symlink to another directory could cause it to incorrectly show files tracked by Git as untracked. see the "status: add a failing test showing a core.untrackedCache bug" commit to git.git. a workaround for that is (and this might work for other undiscovered bugs in the future):
$ git -c core.untrackedCache=false status
this bug has also been shown to affect non-symlink cases of replacing a directory with a file when it comes to the internal structures of the untracked cache, but no case has been reported where this resulted in wrong "git status" output. okay so thatβs a whole mess.
there are also cases where existing indexes written by Git versions before 2.17 will reference directories that donβt exist anymore, potentially causing many "could not open directory" warnings to be printed on "git status". these are new warnings for existing issues that were previously silently discarded. not me finding out the warnings were always there, just hidden.
as with the bug described above, the solution is to one-off do a "git status" run with core.untrackedCache=false to flush out the leftover bad data. do that and youβre good, fr fr.
π¦ FILE SYSTEM MONITOR π¦
okay so this feature is literally here to speed up git operations for repos that have big huge working directories. we're talking large.
it lets git team up with a file system monitor (peep git-fsmonitor--daemon(1) and the "fsmonitor-watchman" section of githooks(5)) that can just tell it which files have been modified. which means git gets to avoid having to lstat() every single file to find the modified ones. the way that saves so much time?? iconic.
and when you use it together with the untracked cache, it gets even better β it can further improve performance by avoiding the cost of scanning the entire working directory looking for new files. no cap, that's a glow-up.
if you want to enable (or disable) this feature, it's way easier to use the core.fsmonitor configuration variable (see git-config(1)) than using the --fsmonitor option to git update-index in each repository. especially if you want to do it across all the repositories you use, because you can set the configuration variable in your $HOME/.gitconfig just once and have it affect all repositories you touch. one and done, bestie. π
heads up tho: when thecore.fsmonitorconfiguration variable is changed, the file system monitor is added to or removed from the index the next time a command reads the index. but when--[no-]fsmonitorare used, the file system monitor is immediately added to or removed from the index. different timing, different vibe. β°
β¨ CONFIGURATION β¨
this command honors the core.filemode configuration variable. if your repository is on a filesystem whose executable bits are unreliable, this should be set to false (see git-config(1)). this causes the command to ignore differences in file modes recorded in the index and the file mode on the filesystem if they differ only on executable bit. on such an unfortunate filesystem, you may need to use git update-index --chmod=. π tragic, but we cope.
quite similarly, if the core.symlinks configuration variable is set to false (see git-config(1)), symbolic links are checked out as plain files, and this command does not modify a recorded file mode from symbolic link to regular file. it justβ¦ doesn't. respect the boundary. π«Ά
the command looks at the core.ignorestat configuration variable. see the Using "assume unchanged" bit section above. (iykyk π)
the command also looks at the core.trustctime configuration variable. it can be useful when the inode change time is regularly modified by something outside Git (file system crawlers and backup systems use ctime for marking files processed) (see git-config(1)). external forces messing with your ctimeβ¦ not the vibe, so there's a knob for it. β
the untracked cache extension can be enabled by the core.untrackedCache configuration variable (see git-config(1)). π
π NOTES π
so bestie, this is important. users often try to use the assume-unchanged and skip-worktree bits to tell Git to ignore changes to files that are tracked. this does not work as expected, since Git may still check working tree files against the index when performing certain operations. π¨
in general, Git does not provide a way to ignore changes to tracked files, so alternate solutions are recommended. periodt.
for example, if the file you want to change is some sort of config file, the repository can include a sample config file that can then be copied into the ignored name and modified. the repository can even include a script to treat the sample file as a template, modifying and copying it automatically. that's the actual play. π
π SEE ALSO π
π GIT π
part of the git(1) suite. one big happy family fr fr. π
aaaand that's a wrap on GIT-UPDATE-INDEX(1)! πΈ this absolute icon of a page comes to you from Git 2.56.0, dated 2026-09-27 β screenshot it, frame it, put it on your wall. πβ¨
π¦ 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