I think it is possible to do something similar with the gitattributes and smudge and clean filters, but that would be dirty and probably pretty fragile. My method is simply to put things that I don’t want to publish in a file without common ~/.bashrc.local and the source file, which is inside a common .bashrc , for example
if [ -r ~/.bashrc.local ]; then . ~/.bashrc.local fi
It also allows me to maintain a system / machine dependent configuration without spinning my global .bashrc .
source share