get-upstream-head-branch call failed on my system.
I changed it to something that worked on my system, which follows the $output convention elsewhere.
Fixed issues with error handling in RUN().
Regarding local in: local foo=$(some command), local has it's own return code which overwrites the return code of the command.  So the existing error handling was only checking for failure of "local".
Introduced more if control structures, to prevent cascading error messages in trouble spots.
Added in caching of when the clone/pull/push occurred into a git config --local option with name "subrepo.lastpushcommitid$subdir"
With the use of this cached information, the merges will work!
As long as the subdir doesn't have any backslaches, the name will work. They'll probably need to be escaped with another backslash, though I didn't look into it too much as I figured a different path would be used due to feedback.
So, it turns out in some flows I made that HEAD^2 doesn't always exist, so I threw HEAD there as a backup.
Feel free to change! But this works for me as everything looks ship-shape.