Ignore files already committed to Git

Have you ever have a situation where you do not want your changes to a particular file to be tracked but you still need it in the repository for future developers?

An example of this would be the new config/secrets.yml in Rails 4.x

secrets.yml acts as a replacement for .env files but unlike .env files, you need secrets.yml in your repository in order not to break your app.

With secrets.yml already committed into your application by default, how do you untrack future changes to it?

First add secrets.yml into your .gitignore in a clean state.

# /.gitignore
config/secrets.yml

Commit your .gitignore

Next, tell git not to track anymore changes by using git update-index

  $ git update-index --assume-unchanged config/secrets.yml

And you’re done!