git-checkout-index - Linux


git-checkout-index updates the working tree to match the content of the index. It is primarily used to discard changes in the working tree that have not yet been staged or committed.


git checkout-index [<options>] <paths>...


  • -a, --all: Checkout all files tracked by the index.
  • -f, --force: Overwrite unstaged changes without prompting for confirmation.
  • --quiet, -q: Suppress output messages.
  • -v, --verbose: Show detailed progress information.
  • <paths>: Space-separated list of files or directories to update.


Checkout a specific file:

git checkout-index file.txt

Checkout all files with force:

git checkout-index -f --all

Checkout only changed files:

git checkout-index -a | grep ^: | cut -d : -f 2

Common Issues

  • Error: paths not found: Ensure the specified <paths> exist in the index and are valid paths.
  • Error: file is modified: Unstaged changes exist in the file you are trying to checkout. Stage or commit the changes before checking it out.
  • No output: If --quiet is not specified, the command will output "Updated 1 paths" for each file that is checked out. If you don’t see any output, check the --quiet option.


git-checkout-index can be combined with other commands for advanced workflows:

  • Update specific files from a different branch: git checkout-index --patch branch:file
  • Unstage and checkout a file: git reset HEAD -- path/to/file && git checkout-index path/to/file

Related Commands

  • git add: Stage changes in the working tree for commit.
  • git checkout: Switch to a different branch or restore files from the index.
  • git clean: Remove untracked files from the working tree.
  • git reset: Unstage and reset changes in the working tree.