I have a .gitignore file like this:
# no binaries
*/
!*.go/
!.gitignore
I thought */ means to ignore all files in all subdirectories (so every file), !*.go/ means to not-ignore all *.go files in all subdirectories, and !.gitignore means to not ignore .gitignore.
However, the issue I have now is that when I create a new *.go file in a subdirectory, it's now ignored.
How do I correctly gitignore all compiled binaries, but not ignore *.go files?
I now have
**/*
!**/*.go
!.gitignore
But it still ignores all *.go files in the ch1 directory. Anyone else have ideas?
This will ignore everything except .go files, and works for subdirectories too:
**/*
!**/*.go
!**/
You may also want to check out this question, which is asking something very similar.
You need to use:
**/*.go
The ** is for ignoring files inside any folder and not only in the current folder.
Allow a later
!/abc/defto override an earlier/abcthat
appears in the same.gitignorefile to make it easier to expresseverything in /abc directory is ignored, except for ....
.gitignore documentation:Two consecutive asterisks (
**) in patterns matched against full pathname may have special meaning:
Leading **
A leading **followed by aslashmeans match in all directories.
For example,**/foomatches file or directoryfooanywhere, the same as patternfoo.**/foo/barmatches file or directory "bar" anywhere that is directly under directoryfoo.
Trailing **
A trailing /**matches everything inside.
For example,abc/**matches all files inside directoryabc, relative to the location of the.gitignorefile, with infinite depth.
/**/A slash followed by two consecutive asterisks then a slash matches zero or more directories.
For example,a/**/bmatchesa/b,a/x/b,a/x/y/band so on.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With