Search code examples
git

gitignore - ignore folders that doesn't respect a specific mask


I need a gitignore that ignores basically all folders with a few exceptions. I have 4 folders that needs to be sync with git 3 of them start like this :

RCU*/

And another folder named Tools. For example : enter image description here

I need to ignore all folders except :

  • RCUFromUR
  • RCUToB360
  • RCUToUR
  • Tools

Every other folders than these needs to be ignored (and other folders will be added), is there a way to achieve this ?

Thanks


Solution

  • # Ignore all directories except specific ones
    /*
    !/RCUFromUR/
    !/RCUToB360/
    !/RCUToUR/
    !/Tools/
    
    # If you want to exclude subdirectories from being tracked under the above folders, you can add these
    !/RCUFromUR/*/
    !/RCUToB360/*/
    !/RCUToUR/*/
    !/Tools/*/