Is it possible? The git update-index --assume-unchanged
is no solution, ignored files have to be tracked. Creating submodules either.
E.g.
cat .customgitignore(1|2|3...)
i-do-not-need-this.extension
cat .gitignore
basic-stuff.extension
<load> .customgitignore1
<load> .customgitignore2
<load> .customgitignore3
etc
Issue description for those interested.
I am creating private repo of configs. One branch = one config. Additional branch as workspace. I merge other branches-configs with workspace depending on requirements. Branches-configs each have their own .gitignore which should be applied only after merge. I am trying to omit conflicts in gitignore file.
As Git doesn't support this out of the box, you may implement one yourself with Git hooks, for example:
In any case, you will need to manage your ignores and includes in a custom file, not a
.gitignore
itself, as this one will be generated. So, let's say, you have a.gitignoreincludes
file in a branch, and custom include files in other branches.So, you may install a "post-merge" hook like this, for example:
This hook will launch on any successful merge, will look for a
.gitignoreincludes
file, and, if it exists, will generate a.gitignore
file..gitignore
will contain all entries from.gitignoreincludes
and all entries from all files referenced asinclude FILE_NAME
. Having.gitignore
ignoring itself allows it to be safely regenerated multiple times when doing merges.This can be further improved by allowing
include
instructions in included files as well, or also apost-checkout
hook can be implemented to regenerate the .gitignore when switching between branches, etc., etc..Then don't version the final .gitignore file itself: generate it on demand.
Keep your .gitignore files separates, but add a content filter driver (a
smudge
script), which will: