Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
Get the name of the remote tracked branch of my local branch for use in script
Can I programmatically get the name of the remote branch which my local branch is tracking?
I'm interested in scripting around git-range-diff(1), so that I could do something like this:
[alias]
rd = range-diff master..REMOTE_BRANCH remote1/master..HEAD
and then be able to run on the command line git rd
to get a range diff between the remote state of my branch and the local one (represented by HEAD).
What should I put in REMOTE_BRANCH to make this work?
1 answer
The following users marked this post as Works for me:
User | Comment | Date |
---|---|---|
alx |
Thread: Works for me Thanks! Exactly what I needed. :-) |
Mar 4, 2025 at 11:58 |
I'm not exactly sure what you want with the whole of rd
, but
…programmatically get the name of the remote branch which my local branch is tracking…
sounds very much like the @{upstream}
/@{u}
shortcut. You can provide a branch before it to refer to the tracked remote of that branch, or leave it bare to refer to the tracked remote of the branch you currently have checked out.
If remote1
is actually the tracking remote for master
, you could even write the alias as
[alias]
rd = range-diff master..@{u} master@{u}..HEAD
0 comment threads