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

  • By
    Create Namespaced Classes with MooTools

    MooTools has always gotten a bit of grief for not inherently using and standardizing namespaced-based JavaScript classes like the Dojo Toolkit does.  Many developers create their classes as globals which is generally frowned up.  I mostly disagree with that stance, but each to their own.  In any event...

  • By
    CSS vs. JS Animation: Which is Faster?

    How is it possible that JavaScript-based animation has secretly always been as fast — or faster — than CSS transitions? And, how is it possible that Adobe and Google consistently release media-rich mobile sites that rival the performance of native apps? This article serves as a point-by-point...

Incredible Demos

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!