Exceptions in .gitignore

How to add an exception to .gitignore, like “ignore all the .dll files BUT myfile.dll”?

  • Setup 'git diff' for special file types
  • Strange .gitignore behavior for emacs temporary files
  • Advantages and drawbacks in committing built files in web develoment
  • Why does git fail to fetch specific valid submodule for a given commit and how to fix it?
  • `git clean` removes ignored files by default?
  • Convert .gitignore to rsync merge filter include file? (with sed or awk)
  • Can't understand how gitignore ignores the folders
  • swipe activity to change another activity in android and show multiple Activity in a singleview?
  • What does “git+” mean in the url?
  • Count Git commits per period
  • How do patches work in Git?
  • What do the Git “pairing broken” and “unknown” statuses mean, and when do they occur?
  • 4 Solutions collect form web for “Exceptions in .gitignore”

    Use ! to negate the pattern:


    If you want to ignore whole folder, except some specific files, then write:


    This won’t work:


    You can also ignore folders like


    you can also ignore nested folder with patterns like


    You can have several .gitignore files working together in a hierarchical manner to achieve your goal.
    At the root level you may have:



    inside the folder having the myfile.dll you can add another .gitignore file like so:



    more info here

    An optional prefix “!” which negates the pattern; any matching file excluded by a previous pattern will become included again. Put a backslash (“\”) in front of the first “!” for patterns that begin with a literal “!”, for example, “!important!.txt”. It is possible to re-include a file if a parent directory of that file is excluded if certain conditions are met. See section NOTES for detail.

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