Search code examples
regexgitgitignore

Gitignore on executable


What would be the format for excluding files that do not have an extension, such as runme, which does not have an extension. For example, if the files in my directory are:

script.sh
script.s
runme

I want to exclude the files without an extension. I suppose the regex for this would be ^[^.]+$. How does this go into a .gitignore though? What are the regex (or is it more unix/shell filepath matching patterns)?


Solution

  • The gitignore file format doesn't support regular expressions, just regular Unix-style patterns.

    In your case, I would exclude everything and then allow the files that do have an extension. For example:

    # Ignore everything
    *
    # Allow directories
    !*/
    # Allow files with an extension
    !*.*
    

    This would include files like these:

    foo.txt
    some/dir/bar.txt
    

    But exclude files like these:

    foo
    some/dir/bar