If the config file is useless to do version control (since you need to config differently in local) you'd better ignore the file in .gitignore
:
touch .gitignore
echo <file> >> .gitignore
git rm <file> --cached
git add .
git commit -m 'message'
git push
The reason why not use git update-index --skip-worktree <file>
as below:
- The config file is not changed locally, but only updated in remote, when you execute
git pull
, the config file will be update as remote.
- The config file both changed in local and remote, when you execute
git pull
, git will detect conflict and shows error as:
error: Your local changes to the following files would be overwritten by merge:
file
Please commit your changes or stash them before you merge.
Aborting
- The config file only changed locally, when you want to checkout other branches, git will show
error: Your local changes to the following files would be overwritten by checkout:
file
Please commit your changes or stash them before you switch branches.
Aborting
git update-index --skip-worktree
is usually for temporarily use.
You can also compare the usage of git update-index --skip-worktree
here.