LinuxCommandLibrary

git-checkout-index

Copy files from the index to working directory

TLDR

Restore any files deleted since the last commit

$ git checkout-index [[-a|--all]]
copy

Restore any files deleted or changed since the last commit
$ git checkout-index [[-a|--all]] [[-f|--force]]
copy

Restore any files changed since the last commit, ignoring any files that were deleted
$ git checkout-index [[-a|--all]] [[-f|--force]] [[-n|--no-create]]
copy

Export a copy of the entire tree at the last commit to the specified directory (the trailing slash is important)
$ git checkout-index [[-a|--all]] [[-f|--force]] --prefix [path/to/export_directory]/
copy

SYNOPSIS

git checkout-index [-a|-u|--all|--update] [-q|--quiet] [--prefix=<prefix>/] [-b|-f|--force] [--stdin] [--stage[=<#>|!]] [--] [<file>...]

PARAMETERS

-a, --all
    Checkout all index entries to working tree

-u, --update
    Update only newer index files, skip others

-q, --quiet
    Suppress all output

-f, --force or -b
    Overwrite existing files without prompt

--prefix=<prefix>/
    Prepend prefix to output paths

--stdin
    Read file list from standard input

--stage[=<#>|!]
    Checkout specific stage number or all non-base

--index-version <n>[,o[,extensions]]
    Use specific index format (plumbing)

--chmod=(+|-)x
    Set executable bit on output files

DESCRIPTION

git checkout-index copies files from the Git index (staging area) to the working tree or specified locations. It restores files exactly as they are staged, bypassing HEAD commit changes. Ideal for scripting, archiving, or populating directories without affecting branches.

By default, it processes listed files. Use -a or --all to checkout everything in the index. --prefix relocates output to a subdirectory, useful for backups or temporary extracts. --force (-f or -b) overwrites existing files; without it, skips modified files.

--update (-u) only refreshes files if index version is newer, preserving local changes. --quiet (-q) suppresses output. Advanced options like --stdin read paths from input, --stage extracts specific conflict stages, and --index-version handles index formats.

This low-level porcelain command complements git checkout for precise index-to-disk operations, often in hooks or builds. It does not update the index itself.

CAVEATS

Overwrites files with --force; backs up nothing. Ignores untracked/modified files unless forced. Plumbing options risky for casual use.

EXIT CODES

0: OK
1: Errors (e.g., write failures)
128: Fatal Git error

COMMON USE

git checkout-index -a --prefix=backup/ archives index.
git checkout-index -u refreshes working tree safely.

HISTORY

Introduced early in Git (pre-1.0, ~2005). Evolved with index formats; stage support added ~1.6.0 for merges. Remains stable porcelain.

SEE ALSO

Copied to clipboard