Reputation: 21
In order to write a specific script, I need to check is the current branch has a tracked remote and what is the name of this remote. Is there a way to get only the name of the branch tacked by the current one, without having to parse git remote show origin
output?
Upvotes: 2
Views: 218
Reputation: 3709
Since 28fb8438 (Introduce @{upstream} notation, 2009-09-10) included in Git 1.7+, you can use the HEAD@{upstream}
(or HEAD@{u}
for short) to achieve this.
For educational purposes, here's a shell script equivalent.
#!/bin/sh
cbranch=`git rev-parse --abbrev-ref HEAD`
cmerge=`git config branch.$cbranch.merge`
cremote=`git config branch.$cbranch.remote`
if [ $? -eq 0 ]; then
echo "$cremote/`git rev-parse --abbrev-ref $cmerge`"
else
return 1
fi
Upvotes: 1