Last active
April 12, 2025 02:48
-
-
Save hieblmedia/9318457 to your computer and use it in GitHub Desktop.
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/ |
+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!
@
@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.
For me worked to re-include every individual parent again, meaning
/**
!/mnt
!/mnt/cassandra
!/mnt/cassandra/analytics-seed
!/mnt/cassandra/analytics-seed/spark
!/mnt/cassandra/analytics-seed/spark/jupyter
...
Thank you!
I wanted to share my example, maybe it would help someone.
My .gitignore
:
# Disable all directories.
*/
!.gitignore
# Enable `Jenkins Service/init.groovy.d`.
!Jenkins Service/
Jenkins Service/*
!Jenkins Service/init.groovy.d/
# Enable `Scripts`.
!Scripts/
After git add .
:
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: .gitignore
new file: Jenkins Service/init.groovy.d/BuildRerunner.groovy
new file: Jenkins Service/init.groovy.d/rerun-last-prod-build.groovy
new file: Jenkins Service/init.groovy.d/rerun-zombie-builds.groovy
new file: Scripts/jenkins-delete-cache.bat
Thanks for the solution!
In my case git add *
must be used after configuration of the gitignore file. Somehow git add .
does not work.
Awesome, thanks!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Worked for me Thanks!