This pushes to a given remote with the right branch name, whatever it is:
git push origin HEAD
Unfortunately you still need to know the remote name for this.
If you want something that works even without knowing the remote name, it's a bit more complicated. The best way I could find was this command, which prints the name of the remote tracking branch, including the name of the remote:
git rev-parse --abbrev-ref --symbolic-full-name @{u}
This outputs in the format remotename/branchname
. From this you can extract the remote name using bash, for example:
refname=$(git rev-parse --abbrev-ref --symbolic-full-name @{u})
IFS=/ read -a arr <<< "$refname"
remote=${arr[0]}
branch=${arr[1]}
And then you can push like this:
git push $remote $branch
# actually this should do as well:
# git push $remote HEAD