Mercurial: Global .hgignore
I've worked with git for several years and one of my favorite git posts is Create a Global .gitignore which details how you can create a global .gitignore
file to ignore certain useless files (think .DS_Store
, node_modules
, etc.) so that you aren't always adding the same files to every repository's .gitignore
file and don't get presented with a bunch of garbage when running git status
.
The team I've been shifted to at Mozilla uses Mercurial instead of git, so you can imagine I'm trying to shake off the git mindset so I can become a Mercurial master. With that said, a trick like a global .gitignore
is philosophy-independent and just a good help. The first step is opening your profile's .hgrc
file and adding the following under the [ui]
section:
[ui] ignore = ~/.hgignore
The above points to the location of a global .hgignore
file. Now open your .hgignore
file and add files and directories which you never want added to any repositories:
.DS_Store .orig node_modules/
Global .*ignore files take a moment to configure and keep paying back by preventing noise and unwanted files in commits. Take the time and enjoy the rewards!
That’s a really useful trick! However, isn’t it most effective when working on projects by yourself? If I understand correctly it means that you wouldn’t be committing the details of the files to ignore so if someone else contributed to the project who hadn’t also configured their global ignores they could end up committing a load of junk files…
Of course you mentioned that in the linked article on doing the same in git which I only read _after_ posting my first comment ;)