git update-index Command in CI
git update-index is the plumbing command that registers file contents and flags in the index.
Most workflows stage via git add, but CI occasionally needs lower-level control: fixing a file mode, or telling Git to stop noticing changes to a file. update-index provides it.
Common flags
--chmod=+x <file>- set the executable bit on a tracked file in the index--assume-unchanged <file>- tell Git to skip checking a file for changes--no-assume-unchanged <file>- undo assume-unchanged--skip-worktree <file>- ignore local edits to a tracked file--refresh- refresh the stat information in the index to match the working tree--add/--remove- explicitly add or remove a path
Example
# Make a committed script executable on a case-insensitive runner
git update-index --chmod=+x scripts/deploy.sh
git commit -m "Mark deploy.sh executable"In CI
git update-index --chmod=+x reliably sets the executable bit even on filesystems that do not preserve permissions, fixing "permission denied" on committed scripts. Use --refresh to clear false "modified" stat differences after a checkout on some runners.
Using this in CI
CI checkouts are shallow and detached by default, which changes the answer this command gives you. Commands that read history, branch names, or tags need the checkout configured for it.
- uses: actions/checkout@v4
with:
fetch-depth: 0 # history, tags, and git describe all need this
- run: |
git rev-parse --is-shallow-repository # expect false
git rev-parse --abbrev-ref HEAD # prints HEAD when detachedKey takeaways
- git update-index --chmod=+x fixes executable bits lost on permission-blind filesystems.
- --refresh clears spurious modified flags caused by stat differences after checkout.
- assume-unchanged and skip-worktree are local-only hints, not a way to ignore committed files.