brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: git update-index --skip-worktree hides a local edit to a tracked file

Git
~/tips/tip-git-skip-worktree-local-change

git update-index --skip-worktree config/local.php

Tells git to treat a tracked file as unchanged so your local edits stop showing up.

Sometimes a project tracks a file that every developer edits locally, such as a config with a database host. You change it for your machine and then see it in every git status. There is a flag for that, with a big warning attached.

git update-index --skip-worktree config/local.php

Git now treats the file as unchanged, so it stays out of git status and out of git commit -a. To undo it:

git update-index --no-skip-worktree config/local.php

To find out which files are marked in a repository, the tag S in git ls-files -v shows them:

git ls-files -v | grep '^S'

Now the caveat, and it is a big one. The manual says the bit was made for sparse checkouts, not for ignoring changes. It states that git does not provide a way to ignore changes to tracked files and that these bits may not work as expected. If the file changes upstream, a pull or merge can still write it or run into conflicts, and then you have to clear the bit by hand.

The manual points to git sparse-checkout for the sparse case. For local settings, a better route is usually a file that is not tracked at all, with a committed config.example next to it. I would use skip-worktree only when I cannot change how the project is set up.

Further reading: git update-index, skip-worktree (Git documentation)

Going deeper: Guide: advanced tmux, a config that grows with you, formats, layouts and more

More Git tips git show-branch main feature git log --stat -5 git merge --no-ff feature -m "Merge feature" git merge --squash feature git merge --abort All Git tips (144) All topics

Link