How can I get tracking information (i.e. remote and branch name) about a specific local Git branch, preferably in one command? There seem to be many ways to do this, e.g.
git rev-parse --abbrev-ref --symbolic-full-name branch_name@{upstream}
However, it returns the upstream in the form 'origin/branch_name', which makes it difficult to figure out the separate parts (e.g. when remote or branch name contains '/'). Is there more reliable solution, preferably using a single Git command?
@RomainValeri in the answer suggested this command to display the tracking information.
However, if you want to get rid of the slash then you can do this
From git-docs,
More on lstrip,
Some examples :
Format :
"%(upstream:remotename):%(upstream:lstrip=-1)"Output :
<remote-name>:<branch-name>Format :
"%(upstream:remotename) %(upstream:lstrip=-1)"Output :
<remote-name> <branch-name>If the branch name includes a slash, then
lstripwon't work. Insteadremoterefcan be used.The output is in this format :
<remote-name> refs/heads/<branch-name>To remove
refs/heads/from the output, pipe the above command to this