How to get the remote name from a local branch?
Note that I do not want the remote tracking branch name but just the remote name.
Consider this contrived example. How do I get prefix/github
?
$ git status -b
## dev...prefix/github/rm/dev
$ git remote
github
prefix
prefix/github
So prefix/github
is the remote and local branch dev
is tracking remote branch rm/dev
.
So far I know this way but it is not fullproof.
$ git rev-parse --abbrev-ref @{u} 2>/dev/null | cut -d'/' -f1
prefix
The prefix/github
remote name is intentional. I can live with keeping my remote without forward slash (in which case the above would work) but wanted to know if I'm missing something.
fyi: I have a bash script where this eventually would be used.
Update:
See this comment for why this question is not a dupe: Get remote name from local branch