On my machine, I\'ve set --skip-worktree
to config/database.yml
.
git update-index --skip-worktree config/database.yml
That isn't a hacky approach at all. It's actually exactly what you need to do in this situation. Let's go through the scenario step by step. (Making a few assumptions along the way because it's a YML file.)
You're ignoring the file because you have changes that only affect your local build process and don't want to accidentally push those changes to others and potentially affect them or, worse yet, production. A fairly normal and good practice.
Sometimes these files do need to be changed, as in this situation, so an updated version gets committed. Pulling in these changes will trigger a check to verify that the file it's overwriting matches the one in the commit and, if not, it throws the error. (Failing the integrity check will ignore the flag)
You're actively ignoring the file, so you need to tell git to care about it again. Otherwise no git process will see the file.
git update-index --no-skip-worktree config/database.yml
Then put your changes somewhere safe, and since you don't want to commit them, stash is the best place:
git stash save "Save changes to config/database.yml"
You can finally bring the changes from the remote into your local branch. You've already fetched when you got the original error, so you can also just do the merge. So:
git pull origin develop
-or-
git merge origin/develop
You're up to date now, but you still want those updates to make it work locally, so let's get them back from our safe storage place:
git stash pop
If there are any conflicts, you can resolve them and make sure your project will build correctly after integrating the new changes.
Finally, we want to protect the other users from our local changes again, so we reinstate the skip-worktree flag on the path.
git update-index --skip-worktree config/database.yml
And we're done.