Table of contents
Open Table of contents
Intro
The other day I was trying to keep a placeholder file on a git repository but wanted it to ignore local changes so people don’t commit things by mistake.
I tried ignoring the file with .gitgnore
and then force adding the empty file with git add PATH_TO_FILE -f
. That didn’t work.
The solution
The way to do it is to add the file to the git repo and after that tell git to skip looking for changes in that file.
git update-index --skip-worktree PATH_TO_FILE
With this command, git
will always assume that the file is up-to-date. You will still be able to pull
changes made to that file.
If you ever want to revert it to the original behavior, you can use git update-index --no-skip-worktree PATH_TO_FILE
.