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
    5 Awesome New Mozilla Technologies You’ve Never Heard Of

    My trip to Mozilla Summit 2013 was incredible.  I've spent so much time focusing on my project that I had lost sight of all of the great work Mozillians were putting out.  MozSummit provided the perfect reminder of how brilliant my colleagues are and how much...

  • By
    Chris Coyier’s Favorite CodePen Demos

    David asked me if I'd be up for a guest post picking out some of my favorite Pens from CodePen. A daunting task! There are so many! I managed to pick a few though that have blown me away over the past few months. If you...

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!