Mercurial: Global .hgignore

By  on  

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!

Recent Features

Incredible Demos

  • By
    jQuery Wookmark

    The first thing that hits you when you visit Pinterest is "Whoa, the columns are the same width and the photos are cut to fit just the way they should."  Basic web users probably think nothing of it but as a developer, I can appreciate the...

  • By
    PHP / MooTools 1.2 Accordion Helper

    The MooTools Accordion plugin seems to be the plugin that people seem to have the most problems with. It's an awesome plugin, so I can see why so many people want to use it, but I think that may be part of the problem.

Discussion

  1. Mark S

    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…

    • Mark S

      Of course you mentioned that in the linked article on doing the same in git which I only read _after_ posting my first comment ;)

Wrap your code in <pre class="{language}"></pre> tags, link to a GitHub gist, JSFiddle fiddle, or CodePen pen to embed!