Search code examples
gitdirectorygitignore

How to exclude folder .gitignore


How can i exclude everything but only specific directory to publish git by using .gitignore

For example my root tree

-node_modules
-js
-ts
-releases 
-package.json

I want to only add releases folder and all contents to my git branch.

What I tried

*
!releases
*
!releases/

Solution

  • It sounds like you're trying to ignore everything by default but whitelist certain directories. If so you may find this post helpful:

    https://jasonstitt.com/gitignore-whitelisting-patterns

    For your scenario you may want to try adding a double wildcard (to allow traversal below that folder) at the end of the folder you want to include like this:

    *
    !folder_name/**