How do I get the name of the remote git
branch from which the local git
current commit was branched-off?
I assume this is a 4 step process, and that the first three steps might be as follows:
Step One: Get the name of the current branch in the local git repo:
git rev-parse --abbrev-ref HEAD
Step Two: Get the hash of the currently checked out commit from the local repo:
git rev-parse HEAD # full hash
Step Three: Get the name of the upstream tracking branch on the remote git repo:
git rev-parse --abbrev-ref @{upstream}
Step Four: Get the name of the parent upstream tracking branch on the remote git repo:
What specific code is required to do this? After reading @ChrisJohnsen's answer to this other posting, I imagine that the solution involves looking for the most recent commit that was derived from another branch in the remote repository. However, the code in the answers to the linked posting all seem to be designed for local repositories. This current question is different because I am asking how to find the remote repository parent branch from a local repository child branch.
I am adding the bash
tag because these commands are running on CentOS servers that can use bash
scripting.