Refactor fetchhead

Check for the remote name (see #2697) and use a convenience function to figure out the name of the upstream remote, instead of figuring it out in the middle of an if condition.