You could also use the @slidewave/gitignore-include NPM package to accomplish the task.
Example:
## <include href="path/to/vim.gitignore">
## </include>
## <include href="path/to/SVN.gitignore">
## </include>
## <include href="path/to/CVS.gitignore">
## </include>
## <include href="https://github.com/github/gitignore/raw/main/Global/macOS.gitignore">
## </include>
## <include href="https://github.com/github/gitignore/raw/main/Global/VisualStudioCode.gitignore">
## </include>
# Any local overrides go here.
Then either
- execute
npx -p @slidewave/gitignore-include giismudge .gitignore
to bring everything together,
- hook up the git hooks to smudge your ignore files on commit, or
- set up a
.gitattribute
filter driver as noted in VonC's answer but using giismudge
to do the work.
Caveat: anyone, including you, who needs to re-smudge the ignore files will need to have the same source files at the same paths in order to make this work. So I recommend placing your source gitignore files into a public repository and using the raw URLs to them similar to what I showed for the macOS and VSCode include directives.
Note that I'm the author of the tool, so I'm a bit biased and am responding as a form of advertising the tool. :)