0

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/
AhmetEnesKCC
  • 69
  • 2
  • 8
  • 1
    This question should probably be reformatted to ask how to exclude everything by default and only include specific files and directories using `.gitignore`. – Mikko Rantalainen Apr 21 '21 at 14:30

2 Answers2

2

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/**
David Lumpkin
  • 174
  • 1
  • 6
0

just mention the folder name in .gitignore like this:

folder_name

if this is not in the same directory, you can do this:

path/to/the/sub_folder
  • i want to exclude it if do in that way it will be included. I will edit my question to be more clear – AhmetEnesKCC Apr 20 '21 at 16:33
  • 1
    Check this out: [link](https://stackoverflow.com/questions/5241644/using-gitignore-to-ignore-everything-but-specific-directories) –  Apr 20 '21 at 16:40