I'm using a bare repository for tracking my dotfiles and trying to filter the passwords and API keys from some of the files.
.gitattributes
some-dotfile filter=remove-pass
.git/config
[filter "remove-pass"]
clean = "sed -e 's/^password=.*/#password=TODO/'"
This works on default repositories but not in a bare.
The
cleancommand is called upon checkin. By default, a bare repository does not have a work tree, and we cannot rungit commitin it. So, thecleancommand in a bare repository is not expected to be invoked in most cases. Commands likegit pushandgit fetchdo not invoke thecleancommand.There is a case in which the
cleancommand configured in a bare repository can work. But it's tricky and rare.The 2 new commits are stored in
/home/me/fooinstead of/home/me/bar/.gitas we specify--git-dir. Now check the content of the committedsome-dotfile,The
catcommand prints#password=TODOso we know thecleancommand takes effect. However, we would unlikely use a bare repository like this.