threads / discuss / 27748

How do I get the name of the parent branch?

Subject: How do I get the name of the parent branch?

## tl;dr

2 messages between Jul 3, 2011 and Jul 3, 2011.

replies: 1people: 2as markdown or json

Bruce Korb· Jul 3, 2011, 16:49 UTC · lore

Google results point to how to get to commits that have gone into parent branches, but fundamentally I just want to have a script that constructs a diff of what has changed since the latest branch without having to do manual research to figure out the name.

As best as I can tell, you use:
    git format-patch -o pdir --ignore-if-in-upstream $branch

the hard part seems to be (but ought not be) figuring out the value for "$branch".

Jay Soffian· Jul 3, 2011, 17:43 UTC · re: Bruce Korb · lore

Re: How do I get the name of the parent branch?

On Sun, Jul 3, 2011 at 12:49 PM, Bruce Korb <bruce.korb@gmail.com> wrote:
Show 11 quoted lines
> Google results point to how to get to commits that have gone into
> parent branches, but fundamentally I just want to have a script
> that constructs a diff of what has changed since the latest branch
> without having to do manual research to figure out the name.
>
> As best as I can tell, you use:
>
>   git format-patch -o pdir --ignore-if-in-upstream $branch
>
> the hard part seems to be (but ought not be) figuring out
> the value for "$branch".

Depending upon how you created the currently checked out branch, git recorded the parent (which is usually referred to as the "upstream" branch these days) in .git/config, and you can get this information thusly:

  $ git rev-parse --abbrev-ref @{upstream}

(But you should not be afraid to look at .git/config and see where this information is recorded. Look for a section named [branch "$branch].)

Of course, you can use @{upstream} directly:
  $ git log @{u}..  # @{u} is a synonym for @{upstream}
  $ git diff @{u}
j.

← back to recent threads