4

I've got some config files (.idea/) from an IDE in my working directory, and Git lists these as Untracked files. Should I

  1. add these to the .gitignore (which will get pushed to the main repo), or
  2. use the local option of

    git update-index --assume-unchanged <name of file>
    
  3. or follow a different approach altogether?

What's best practice?

jub0bs
  • 60,866
  • 25
  • 183
  • 186
Snowcrash
  • 80,579
  • 89
  • 266
  • 376
  • Yes. Or No. Maybe. It depends on whether you want to preserve changes to those files or not. Some IDEs store some configuration that might be useful to retain. Many store a whole bunch of useless (in the sense that it's redundant and can easily be regenerated) metadata... – twalberg Nov 10 '14 at 20:48

3 Answers3

8

Those files are specific to your own machine/setup. You should indeed ignore them.

However, you should not simply add entries corresponding to those files in the project's .gitignore. Instead, you should ignore those files via a global .gitignore:

git config --global core.excludesfile <path-to-global-ignore-file>

Why not just add entries in the project's .gitignore? Remember that this file is going to be used by all collaborators in the project, so you want to keep it clean and tidy; adding user-specific entries to a repository-specific .gitignore will just bloat/pollute the latter, and contribute to unnecessary mental overhead.

For instance, imagine that one collaborator, Bob, works on Mac OS X, whereas another collaborator, Alice, works on Windows. Bob probably wants to ignore .DS_Store files, whereas, Alice probably wants to ignore thumbs.db files. However, Bob has no need to ignore thumbs.db files, and Alice has no need to ignore .DS_Store files. Therefore, they shouldn't inflict a useless gitignore entry on each other. They would do better to ignore such files via a .gitignore file local to their machines.

jub0bs
  • 60,866
  • 25
  • 183
  • 186
  • 1
    What would be a good reason to not do that? How would it be polluting the `.gitignore` file? – Makoto Nov 10 '14 at 20:00
  • 1
    What's the problem here exactly? Unless everyone is running a different OS, is there anything objectionable about handling OS-specific files? Personally, if someone I'm collaborating with adds a .gitignore line that ignores files auto-generated by Mac OSX, I'd welcome it, since it saves me the effort of configuring it myself. – Duncan Malashock Dec 15 '14 at 20:19
  • @DuncanMalashock *Unless everyone is running a different OS [...]* That's precisely the case in which you want to use a user-specific gitignore. In general (e.g. in most open-source projects), you can't predict the OS used by your collaborators. Keeping all those OS-dependent entries in the project's `.gitignore` would make it very messy very quickly. – jub0bs Dec 20 '14 at 18:14
  • Adding them to the project's `.gitignore` will also prevent others from adding those files, eliminating the need for everybody involved to have to set up their personal global `.gitignore`s. If you only add them to your global `.gitignore`, someone else might not have done that and inadvertently added the file to the repo, which is what you want to avoid. I'd suggest doing both: adding the files to both the global and the project's `.gitignore`. – Tonio May 14 '15 at 21:23
  • @Tonio But then, you have to cover all such files from all operating systems used by contributors on the project. So wasteful. – jub0bs May 14 '15 at 21:40
  • Somewhat, yes, but safer. – Tonio May 14 '15 at 21:40
  • 1
    @Jubobs - you have converted another developer... I understand your logic. Before contributing to any project, the developer should take the responsibility to have a global .gitignore setup to keep their contributions clean. – John Spiteri Dec 10 '16 at 18:18
1

The .idea folder and its associated .iws, .ipr, and .iwl files are really meant for your machine only. The best practice is to add them to .gitignore.

Makoto
  • 104,088
  • 27
  • 192
  • 230
  • -1 If you mean the project's `.gitignore` file, then what you recommend is not good practice. User-specific gitignore entries should not go into the project's `.gitignore` file, simply because the OP's collaborators may not need to ignore files such as `.idea/`. The project's `.gitignore` file should only reflect project-specific ignored files. – jub0bs Nov 10 '14 at 21:36
1

IDE specific files should always be ignored. Unless maybe everyone in your team is working with the same IDE, then it might be useful keeping some. But most of the time it's not.

If you choose to 'remove' them locally, there is always the risk of someone forgetting to do that, so it might be best to just put it in a gitignore.

Here is a list of IDE specific gitignore files that you can use
https://github.com/github/gitignore/tree/master/Global

Tim
  • 41,901
  • 18
  • 127
  • 145