Git list of remote branches
The Trim() operation should do what you want.
$allTrimmedBranches = @()
foreach($branch in $allBranches) {
$allTrimmedBranches += $branch.Trim()
}
#do function
$branches = git for-each-ref --format='%(refname:short)' refs/remotes/origin