In my case the error was occurring when I was trying to git submodule sync. In that case you need to update .git/modules/<submodule_name>/HEAD file instead.
git submodule sync
.git/modules/<submodule_name>/HEAD