git ignore multiple matching files

I try to ignore file in a directory by relative path. E.g. I have several directories in working tree lib/file.f and I want all occurrences of this file to be ignored. I tried


but this does not work.

  • Getting complete history of an SVN repo that's been renamed using git-svn
  • Oauth Cloning on github not working (fatal: Authentication failed)
  • Where can I find info about the syntax of column.status?
  • Why is my GIT Submodule HEAD detached from master?
  • How to work with (sub)directory renames in Git?
  • Does Git store amends?
  • Where does git store its reflog?
  • How to share a branch with other developers under git
  • Merge conflicts but no differences between commits
  • git undo all uncommitted changes
  • Git push branch error after pull rebase
  • How to add image icon on the left of Github Repository' description
  • 3 Solutions collect form web for “git ignore multiple matching files”



    in your .gitignore. This will cause git to ignore any file of the form project/<DIR>/lib/file.f, assuming .gitignore is in the project directory.
    To make git ignore lib/file.f two directories down, you’d also have to add


    to the .gitignore, and so on.

    Vastly simpler of course, would be to place


    in .gitignore to block all files named file.f, but your question seems to suggest there is at least one file by that name you wish not to ignore.

    also you might want to remove the file from git cache, in order to check what you just ignored:

    git rm --cached lib/file.f

    this is if you already added the file to git index

    If you want to specify all sub-folders under specific folder use /**/. To ignore all file.f files in a /src/main/ folder and sub-folders use:

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