How do I ignore a directory in the root of my git repository, but include it further down in the tree?

I need to use .gitignore to exclude a directory in the root of my repository. However, other directories with the same name exist deeper in the directory tree, and I need those to be included. It seems that when I put the name of the directory into .gitignore, it catches all of these directories, not just the one I need to ignore. I understand that .gitignore is actually not a list of files, but patterns. So how can I construct a pattern to ignore just a file in my root directory, but not files with the same name further down?

  • How can I diff two branches with fugitive?
  • Git push hangs when pushing via ssh
  • GitLab CE clone project by web GUI: fatal: unable to access… Couldn't resolve host … because password has character “@”
  • Git commit stats per file
  • Deploying when push to git
  • Uploading Specific Vendor files with Laravel's Envoyer
  • Can changes in the same file be split to different commits in git?
  • github pull requests: Conflicting advice on commit ranges?
  • Does Mercurial have an equivalent to git clean?
  • Two development stages with git
  • How to manage multiple projects in git with different emails?
  • Is there a way to get the affected files of a commit with a git post-commit hook?
  • One Solution collect form web for “How do I ignore a directory in the root of my git repository, but include it further down in the tree?”

    Use a leading /

      /file.x
    

    That will only match a top level file.x but not one lower down, in “want/file.x”, say.

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