Shouldn't this be:
`local remote_name=$(cd $repo; git config branch.$ref.remote 2>/dev/null)` ?