DEV Community

Cover image for A Quick Way To Locally Ignore Files From Git.
Emmanuel Hayford
Emmanuel Hayford

Posted on • Edited on

A Quick Way To Locally Ignore Files From Git.

Often times, I've found myself having to git ignore some files that I shouldn't be pushing to a repository on GitHub, so I'd do something like git add file.rb another_file.rb selectively just so I can commit only the files that I want to make changes to. This is tedious, not to mention a huge waste of time.

If you're familiar with Rails, sometimes you'll need to make a change to your database.yml or even to your Gemfile. Changes you make to these files are only specific to you and you don't need to push this for everyone else, neither do you want to edit .gitignore.

Here's an easy way to locally ignore your changes so you don't have to keep tracking them mistakenly or spend time to selectively track some files.

I added these commands to my aliases so they're easy to access:

alias untrack='git update-index --assume-unchanged'

You can use this like so: untrack database.yml

To undo this you'd do track database.yml but only if you've added track='git update-index --no-assume-unchanged' and of course untrack and track can be anything you choose.

Happy coding!

Top comments (0)