It is difficult to find the parent-branch in git ...
My current solution:
git show-branch -a 2>/dev/null \
| grep '\*' \
| grep -v `git rev-parse --abbrev-ref HEAD` \
| head -n1 \
| perl -ple 's/\[[A-Za-z]+-\d+\][^\]]+$//; s/^.*\[([^~^\]]+).*$/$1/'
Source: https://stackoverflow.com/a/74314172/633961
Why is it difficult to find the parent-branch in git?
This question is not about "how to solve this?". It is about "why is it not straight forward?"
git doesn't store anything about branches.
A commit is an object which points to its parent, and you will have a relationship between commits, but a branch is just a name that points to a commit -- a shallow reference with no extra data.
In standard git, there is no information stored which keep track of : "branch x was initially created from y, then was merged with branch z on june 16th, then was reset on that day, then ...".
You can only do guess work based on the current commit graph, and the current state of other branches.
This guess work leads to commands such as the one you quoted.
You should also note that depending on the way you manage branches in your own repository, some of these commands may work for someone else but not for you.