Meaning of leading slash in `.gitignore` file

If I put a pattern in a .gitignore file with a leading slash, does the slash refer to the directory in which the .gitignore file is located, or does it refer to the root of the whole repository?

(The man pages I have found have hidden this information carefully.)

  • Forked a project but what is .pp?
  • How do I transfer a git repo to my other computer?
  • How do you reset the stored credentials in 'git credential-osxkeychain'?
  • What is a “merge bubble”?
  • How to automatically verify all committers PGP-sign their commit
  • why git-svn failed with signal 13?
  • vim syntax highlighting for git commit messages - custom commentchar
  • Paperclip files get deleted after each deploy
  • Jenkins Build Using Git with Deploy Key
  • Git Grep color options explained and/or compared
  • error: unable to find utility “git”, not a developer tool or in PATH
  • Fastest way to get git status in bash
  • One Solution collect form web for “Meaning of leading slash in `.gitignore` file”

    This is the documentation text:

    • A leading slash matches the beginning of the pathname. For example, “/*.c” matches “cat-file.c”
      but not “mozilla-sha1/sha1.c”.

    These are my guesses:

    • If you use an in-repository-.gitignore, the directory in which the .gitignore
      is located – it is not really useful to make it relative to the repository root.

      A short experiment with same-named files in the repository root and a subdirectory (and a
      .gitignore in this same directory) confirms this.

    • If you use an .git/info/exclude or core.excludesfile, I suppose it is relative
      to the repository root.

      Also this is (for info/exclude) confirmed by the same test (both tests on 1.7.3.4).

    Schnouki found the right part of the documentation about this (emphasis mine):

    • […]
    • Patterns read from a .gitignore file in the same directory as the path, or in
      any parent directory, with patterns in the higher level files (up to the toplevel
      of the work tree) being overridden by those in lower level files down to the
      directory containing the file. These patterns match relative to the location of
      the .gitignore file.
      A project normally includes such .gitignore files in its
      repository, containing patterns for files generated as part of the project build.
    • […]

    One could say that this fact could have been repeated again at the later part quoted above, for clarity.

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