I've had to add sensitive data (database connection details, API keys etc) to files that can't be added to .gitignore many times. I do this by committing the file with variable placeholders...
$secret = 'XXXXXXXXXX';
...then use the following command to ignore my future changes:
git update-index --assume-unchanged /path/to/file
If I need to make a change to this file in the future, I can remove my credentials, use placeholders as above, and issue the following command to have changes tracked again:
git update-index --no-assume-unchanged /path/to/file