Skip to content

[git] Get parent branch and diff since it (suggestion included) #1614

@nahoj

Description

@nahoj

I use AI to review merge requests. The assistants I use all support git natively. However, they don't know how to check all changes since the parent branch, because the "parent branch" is not a standard git concept.

So every time I just give the AI the parent branch name or the command to get it.

It would be nice if the git MCP offered this function.

Here is the command I use; I think it is a reasonable definition of a parent branch:

Find the first commit on the current branch that is on a branch other than the current branch or any remote with the same name.
Print the name of any such branch.

current_branch=$(git rev-parse --abbrev-ref HEAD) && \
for commit in $(git rev-list HEAD); do \
  other_branch=$(git branch -a --contains $commit | \
                /usr/bin/grep -Ev -m 1 "^[ *]*(remotes/.*/)?$current_branch$" | \
                sed -r 's#^[ *]*(remotes/)?##' | \
                xargs); \
  [[ -n "$other_branch" ]] && echo "$other_branch" && break; \
done

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions