Gitignore - Exclude all except specific subdirectory
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# If all files excluded and you will include only specific sub-directories | |
# the parent path must matched before. | |
# | |
/** | |
!/.gitignore | |
############################### | |
# Un-ignore the affected subdirectory | |
!/libraries/ | |
# Ignore subdirectory and all including directories and files to match pattern as valid for the next pattern | |
/libraries/** | |
# This pattern only works with the two previous patterns | |
# (i remember it was working alone on older git versions) | |
!/libraries/myLibrary/ | |
############################### | |
# Another example | |
!/templates/ | |
/templates/** | |
!/templates/myTemplate/ |
If the affected folder is not in the root level of the .gitignore, the solutions above didn't work, however this does:
! templates/ **/templates/* !**/templates/myTemplate
This is exactly what I needed and worked for me. Thanks!
And here is how to exclude only one folder in the root:
/**
!/.gitignore
!/dir
!/dir/**/*
@anisriva have you read the comments above?
@
@anisriva have you read the comments above?
@martin-braun yes i did, and i specifically tried yours as well it seem to only work for the immediate child directory.
Thanks
I removed one star for it to work
!/templates/ /templates/* !/templates/myTemplate/
Worked for me Thanks!
+1 to FabianUx
Did not work for me with two asterisks, but is perfect with only one. Thanks!
Thanks bro!
Thankssss !!!! helped me a lot!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If the affected folder is not in the root level of the .gitignore, the solutions above doesn't work, however this does: