parent branch / base branch
Unfortunately, it is not possible to find the name of the parent/base branch.
Git stores commits and pointers, not branch ancestry.
That means:
- a branch is just a movable name that points to one commit
- Git knows commit parents, but not "this branch was created from that branch"
- after more commits, rebases, merges, or deleted branches, that information is gone
But Git cannot reliably tell you:
- "feature-2 was created from feature-1"
If you are not asking Git about branch ancestry, but the hosting platform about the current PR, then CLI tools can help:
- GitHub:
gh pr view --json baseRefName --jq .baseRefName - GitLab:
glab mr view --output json | jq -r .target_branch
If you use VS Code, it stores the per-branch base automatically in
branch.<name>.vscode-merge-base. Other tools (like my
pre-commit-sync-branch tool) use that value,
too. You find vscode-merge-base in .git/config.