remove grep and use rev-parse
expect head instead of an empty string branches

If the branch is detached, git rev-parse will return HEAD, instead of an
empty string.
Dont set upstream if ref is HEAD

If the ref is HEAD, the we should be in a detached HEAD, and thus don't
have a remote, so there is no point in setting this.
Merge pull request #14803 from saltstack/bp-14774

Backport #14774 to 2014.7