Is it safe to use the same ignores file for Git, Mercurial, and Bazaar?

Git, Mercurial, and Bazaar all seem to have similar formats for their ignore file (.gitignore, .hgignore, .bzrignore [see also bzr patterns]).

In order to improve synchronization of the global ignore files, would it be safe to use one as an actual file and simply symlink the other two to that file? In other words, is there any danger in making my $HOME/.gitignore the canonical ignores file and doing

ln -s $HOME/.gitignore $HOME/.hgignore
ln -s $HOME/.gitignore $HOME/.bazaar/ignore

or is there some subtle difference among them that would bite me at some point?

  • Recommended DVCS mechanism for hosting many independent patches
  • git commands as hg commands
  • How to move bugfixes across branches in DVCS?
  • Versioning with Visual Studio 2010 and HG
  • What's the best way to manage multiple dependent projects in Git or Mercurial?
  • Renaming in Git and Mercurial: Accuracy and automaticity
  • Using Git or Mercurial, how would you know when you do a clone or a pull, no one is checking in files (pushing it)?
  • Mercurial v Git v Subversion
  • 2 Solutions collect form web for “Is it safe to use the same ignores file for Git, Mercurial, and Bazaar?”

    The syntax used in the ignore files is different from system to system:

    • Mercurial: list of regular expressions — can be changed with a syntax: glob line.

    • Bazaar: list of shell glob patterns — prefixing with RE: to match as regular expression.

    • Git: list of shell glob patterns.

    Furthermore, the exact rules for how the shell patterns and regular expressions are matched differ from tool to tool. All in all, this means that you can only hope to use this trick if your global ignore file is pretty simple. Otherwise the differences can come and bite you, as you say.

    I tested it with this file:

    syntax: glob
    .bzr
    .git
    .hg
    *.o
    *~
    

    and it seems to work as intended across all three tools. To test it, I created this directory tree:

    $ tree
    .
    |-- foo.c
    |-- foo.c.~1~
    |-- foo.h
    |-- foo.o
    `-- src
        |-- bar.c
        |-- bar.c.~1~
        `-- bar.o
    

    and ran the status command for each tool:

    $ for tool in hg git bzr; do echo "== $tool status =="; $tool status; done
    == hg status ==
    ? foo.c
    ? foo.h
    ? src/bar.c
    == git status ==
    # On branch master
    #
    # Initial commit
    #
    # Untracked files:
    #   (use "git add <file>..." to include in what will be committed)
    #
    #       foo.c
    #       foo.h
    #       src/
    nothing added to commit but untracked files present (use "git add" to track)
    == bzr status ==
    unknown:
      foo.c
      foo.h
      src/
    

    As you can see, this simple file works fine.

    Technically, Git and Bazaar will now ignore a file called syntax: glob, but unless you plan to create a file with that weird name, this doesn’t matter. Finally, note that Mercurial doesn’t read a $HOME/.hgignore file by default. But you can make it read it by adding

    [ui]
    ignore.my-default = ~/.hgignore
    

    to your $HOME/.hgrc file.

    Syntax of at least Git and Mercurial differ (glob and regex patterns in hg), don’t forget also filesets in hg, ! conditions in bzr

    Git Baby is a git and github fan, let's start git clone.