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
    Image Manipulation with PHP and the GD Library

    Yeah, I'm a Photoshop wizard. I rock the selection tool. I crop like a farmer. I dominate the bucket tool. Hell, I even went as far as wielding the wizard wand selection tool once. ...OK I'm rubbish when it comes to Photoshop.

  • By
    Google-Style Element Fading Using MooTools or jQuery

    Google recently introduced an interesting effect to their homepage: the top left and top right navigation items don't display until you move your mouse or leave the search term box. Why? I can only speculate that they want their homepage as...

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!