Ignore all subdirectories except one in .gitignore

Viewed 84

I am trying to setup gitignore to exclude all subdirectories except for 2. I have included ~!~ for the two i want to include but Sourcetree does not pick it up.

Here is my relevant gitignore

# .gitignore
node_modules/
wp-content/plugins/
wp-content/upgrade/
!wp-content/plugins/export-tool
!wp-content/plugins/darwin_checkout_tracking

The two files were set to be included just not. Before they were excluded.

2 Answers

The /* is important, you must do:

# .gitignore
node_modules/
wp-content/plugins/*
wp-content/upgrade/*
!wp-content/plugins/export-tool
!wp-content/plugins/darwin_checkout_tracking

And it works

you can try this :

# .gitignore
!wp-content
node_modules/
wp-content/plugins/*
wp-content/upgrade/*
!wp-content/plugins/export-tool
!wp-content/plugins/darwin_checkout_tracking
Related