0

I want to get the parent name of the current branch.

for example: I have the following graph:

enter image description here

If I change my current branch to A (git checkout A) I want to get the name of the paranet branch (master)

And if I change my current branch to B (git checkout B) I want to get the name of the paranet branch (A)

I looked here:

How to find the nearest parent of a Git branch? but it didn't give me the results I want:

git log --graph --decorate

gives me:

git branch -a
  A
* B
  master
  remotes/origin/A
  remotes/origin/master

git log --graph --decorate
commit e3a6137ad7697faf74bfffb784249ffbd061f9e8 (HEAD -> B, origin/A, A)
...
 commit 8c4564d8800aebc0d374449f4040a7ae0dfabf9c (origin/master, master)

or:

 git checkout A

 git log --graph --decorate
 commit e3a6137ad7697faf74bfffb784249ffbd061f9e8 (HEAD -> A, origin/A, B)
 commit 8c4564d8800aebc0d374449f4040a7ae0dfabf9c (origin/master, master)

moreover there is no command git parent

so how can I get the name of the parent branch ?

Boom
  • 1,145
  • 18
  • 44
  • 4
    I do not think there is a concept of a “parent” branch. A branch is a pointer to a commit. – evolutionxbox Aug 31 '20 at 15:15
  • 2
    Especially [the answer from VonC](https://stackoverflow.com/a/3161347/10871900) mentioning `git branch --contains ` – dan1st Aug 31 '20 at 15:22

0 Answers0