Keep Controversial Git Opinions to Yourself (And Out of .gitignore)

I work in a shared Git repository with an engineer who insists on committing his .idea/ folder so the team can share run and build configurations. Initially I assumed it was a mistake so I added the folder to the .gitignore just like I have done in virtually every .gitignore that I have ever checked in to a repo. Problem solved.

Before long I noticed that Git was tracking these files again as he had removed the rule from the .gitignore. The ensuing conversation revealed his well intentioned motivations and convinced me that it was fine.

Running git checkout -- .idea before adding files had become second nature but after several months I had finally had enough. Fortunately Git has a solution for teammates with differing .gitignore philosophies. Every repo contains a file .git/info/exclude. It is essentially a .gitignore that isn't committed to the repo so the rules you set will only apply to you.

# git ls-files --others --exclude-from=.git/info/exclude
# Lines that start with '#' are comments.
# For a project mostly in C, the following would be a good set of
# exclude patterns (uncomment them if you want to use them):
# *.[oa]
# *~
.idea

Since Git was already tracking some of these files I also had to run this from the .idea/ directory:

git ls-files | tr '\n' ' ' | xargs git update-index --skip-worktree  

And it hasn't been a problem since.

Devon Moss

Read more posts by this author.