Skip to content

checkout-index Git Command Guide

The git checkout-index command is used to copy files from the index to the working tree. By default it doesn’t overwrite existing files and is primarily used in scripts for fine-grained control over index-to-worktree operations.

Terminal window
git checkout-index [-u] [-q] [-a] [-f] [-n] [--prefix=<string>]
[--stage=<number>|all] [--temp] [--ignore-skip-worktree-bits]
[-z] [--stdin] [--] [<file>...]
OptionDescription
-u, —indexUpdate stat information in index
-q, —quietSuppress output for missing/overlapping files
-a, —allCheckout all files in index (except skip-worktree)
-f, —forceForce overwrite of existing files
-n, —no-createRefresh existing files, don’t create new
—prefix=Prepend path when creating files
—stage=all
—tempWrite to temporary files instead of working directory
—ignore-skip-worktree-bitsInclude files with skip-worktree bit
-zUse NUL-separated input (with —stdin)
—stdinRead file list from standard input
Stop interpreting arguments as options
ParameterDescription
[…]Specific files to checkout (default: none)
Terminal window
git checkout-index -a

Checkout all files from the index to the working directory.

Terminal window
git checkout-index -f -a

Force checkout of all files, overwriting existing ones.

Terminal window
git checkout-index -u -a -n

Update index stat info for all existing files without creating/updating content.

Terminal window
git checkout-index README.md script.sh

Checkout only the specified files from the index.

Checkout merge conflict resolutions (our side)

Section titled “Checkout merge conflict resolutions (our side)”
Terminal window
git checkout-index --stage=2 conflicted-file.txt

Checkout stage 2 (our side) of conflicted-file.txt.

Terminal window
find . -name "*.txt" -print0 | git checkout-index -z --stdin

Checkout all .txt files found by find command.

Terminal window
git checkout-index --prefix=export/ -a

Checkout all files to export/ subdirectory.

Terminal window
git checkout-index --temp --stage=all conflicted-file.txt

Create temporary files for all stages of conflicted-file.txt.

How do I checkout all files from the index?

Section titled “How do I checkout all files from the index?”

To checkout all files from the index, run:

Terminal window
git checkout-index -a

To force overwrite of existing files, use the -f option:

Terminal window
git checkout-index -f -a

How do I access different sides of merge conflicts?

Section titled “How do I access different sides of merge conflicts?”

To access specific sides of merge conflicts, use —stage:

Terminal window
git checkout-index --stage=2 conflicted-file.txt # our version
git checkout-index --stage=3 conflicted-file.txt # their version

How can I read file list from standard input?

Section titled “How can I read file list from standard input?”

To read file list from standard input, use —stdin:

Terminal window
echo -e "file1.txt\nfile2.txt" | git checkout-index --stdin

How do I prepend a path to checked-out files?

Section titled “How do I prepend a path to checked-out files?”

To prepend a path to checked-out files, use —prefix:

Terminal window
git checkout-index --prefix=backup/ file.txt

What’s the difference between checkout-index and checkout?

Section titled “What’s the difference between checkout-index and checkout?”

git checkout works on commits/trees, while checkout-index works only on the index. checkout-index is lower-level and doesn’t modify HEAD or branch state.

To update stat information without changing file contents, use -u -n:

Terminal window
git checkout-index -u -n file.txt

Applications of the git checkout-index command

Section titled “Applications of the git checkout-index command”
  1. Scripting automated file extraction from index
  2. Batch operations on tracked files
  3. Resolving merge conflicts by accessing specific stages
  4. Creating backups of indexed file states
  5. Integration with external diff tools and workflows
  6. Selective file operations in build scripts