(cherry picked from afca957396) From PR: Fix UnboundLocalError remote_head in git (#19057)
afca957396