Skip to content

Instantly share code, notes, and snippets.

@hieblmedia
Last active April 15, 2023 01:33
Embed
What would you like to do?
Gitignore - Exclude all except specific subdirectory
#
# 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/
@martin-braun
Copy link

martin-braun commented Oct 8, 2021

@anisriva have you read the comments above?

@anisriva
Copy link

anisriva commented Oct 8, 2021

@

@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.

@TommyQC
Copy link

TommyQC commented Apr 19, 2022

Thanks

I removed one star for it to work

!/templates/
/templates/*
!/templates/myTemplate/

Worked for me Thanks!

@leandrosoares6
Copy link

+1 to FabianUx

Did not work for me with two asterisks, but is perfect with only one. Thanks!

Thanks bro!

@lucaslgr
Copy link

Thankssss !!!! helped me a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment