Ignore local files in Git without changing the shared .gitignore

Use the repository exclude file or a global ignore file for personal untracked files. Understand why skip-worktree does not reliably ignore tracked edits.

Best practices
Illustration of Git branches and version history

Put personal rules for untracked files in the repository's info/exclude file. They use the same pattern syntax as .gitignore but are not committed or shared with other clones. For rules that should apply across your repositories, configure a global ignore file.

Ignore files in this repository only

In a conventional checkout, the file is .git/info/exclude. To resolve the path correctly when .git is a pointer file, ask Git for it:

exclude_file=$(git rev-parse --git-path info/exclude)
printf '%s\n' 'my-local-notes/' '*.local.js' >> "$exclude_file"

This appends two rules without changing the project's shared .gitignore. Linked worktrees can share repository metadata, so local-to-this-repository does not necessarily mean unique to one worktree.

Ignore personal files across repositories

git config --global core.excludesFile "$HOME/.gitignore_global"
printf '%s\n' '.idea/' '.DS_Store' >> "$HOME/.gitignore_global"

Inspect an existing core.excludesFile setting before replacing it; you may already have a personal ignore file. Repository .gitignore rules take precedence over these lower-priority sources when patterns conflict.

Tracked files need a different design

Ignore patterns do not hide edits to tracked files. For local configuration, keep a template or default configuration in Git, and let the application load a separate ignored override file or environment variables.

You may encounter this workaround:

git update-index --skip-worktree -- config/database.yml

The bit is primarily intended for sparse checkout. It is not a supported promise that Git will ignore arbitrary edits forever, and it can complicate checkout, merge, and stash behavior. Do not rely on it to preserve a private configuration or hide a secret. Clear it before reconciling the file:

git update-index --no-skip-worktree -- config/database.yml

Clearing the bit does not start tracking the file again: it was tracked all along.

FAQ

Is assume-unchanged a better alternative?

No. It is a performance hint based on the assumption that a tracked file has not changed. Git's FAQ advises against using either bit as a tracked-file ignore mechanism.

Do local exclude rules survive a fresh clone?

No. Copy or recreate them if needed. A configured global ignore file continues to apply on the same machine and account, but is not automatically transferred with the repository.

How can I find paths with skip-worktree set?

Use git ls-files -t and inspect entries marked S. If using -v instead, assume-unchanged entries use lowercase markers, so a filter for uppercase S alone can miss a path with both bits set.

See gitignore, Git's tracked-file FAQ, git-update-index, and git-ls-files.

Get a tailored plan

Contact us

Join the community

Scan with WeChat
to join the community

Try Guance

Start online and pay only for what you use.

Get started

Choose a Guance plan

Code hosting