only checkout a repo's original branch at the end

was being reset prematurely, making the submodule commit have nothing to
commit
Merge pull request #2689 from dimagi/fix-rebuildstaging-submodule-issue

only checkout a repo's original branch at the end