For those who want a ready-made set of .gitattribute files you can simply drop on your project, here's this fancy GitHub link.
https://github.com/gitattributes/gitattributes
Once you add a .gitattributes file to your project, make sure you push a commit that re-normalizes all relevant files:
git rm --cached -r . git reset --hard
I think this all comes down to having the right mental model.
In this case, I think it helps to know that:
The zany behavior is that if you set up your function to push for a move (i.e., force a local variable to be treated as a temporary), the language ceases to be able to apply its optimization.
That's basically it. No real mystery.