# Ask for feature on git

5 messages from 2024-09-03 to 2024-09-04. Participants: Loredana Tralli, Simon Richter, Konstantin Khomoutov.
Thread: https://gitlist.dev/t/62042

## Loredana Tralli, 2024-09-03 08:18

Subject: Ask for feature on git
Message-ID: <CAEO06G+SLu-LAe0mkR3ZbaL0MZpBm9PhntQjF-YwVPMtnuH=rQ@mail.gmail.com>
URL: https://gitlist.dev/e/CAEO06G%2BSLu-LAe0mkR3ZbaL0MZpBm9PhntQjF-YwVPMtnuH%3DrQ%40mail.gmail.com

```
Hello,
I'm a developer and I really use and love git. I'd really want to
thank you for your big work

I'd like to ask if exists or if it's possible to implement a feature.
Is it possible to have a git command to find out which is the parent branch?

Thanks and Best Regards,
Loredana Tralli

```

## Simon Richter, 2024-09-03 13:33

Subject: Re: Ask for feature on git
Message-ID: <45a51124-7249-4678-a723-4ab9f82a5f2e@hogyros.de>
URL: https://gitlist.dev/e/45a51124-7249-4678-a723-4ab9f82a5f2e%40hogyros.de
In-Reply-To: <CAEO06G+SLu-LAe0mkR3ZbaL0MZpBm9PhntQjF-YwVPMtnuH=rQ@mail.gmail.com>

```
Hi,

On 9/3/24 17:18, Loredana Tralli wrote:

> Is it possible to have a git command to find out which is the parent branch?

You can ask for the "upstream" branch of a given branch, using the 
"@{upstream}" syntax, that is documented briefly in the git-rev-parse(1) 
manual page.

The upstream branch is automatically set if you check out a branch name 
that only exists in a remote repository but not locally (then, a local 
branch is created), or explicitly set with "git branch --set-upstream-to".

    Simon

```

## Konstantin Khomoutov, 2024-09-03 17:04

Subject: Re: Ask for feature on git
Message-ID: <20240903170438.nhcnojx6upsxsj6d@carbon>
URL: https://gitlist.dev/e/20240903170438.nhcnojx6upsxsj6d%40carbon
In-Reply-To: <CAEO06G+SLu-LAe0mkR3ZbaL0MZpBm9PhntQjF-YwVPMtnuH=rQ@mail.gmail.com>

```
On 9/3/24 17:18, Loredana Tralli wrote:

> Is it possible to have a git command to find out which is the parent branch?

Please try to specify what you consider to be a "parent branch" in your
workflow. The problem is that there are multiple things in Git which may match
what you are asking for. Even better would be to try to explain your original
problem you're struggling with - which made you want the feature being
discussed.

Still, please consider that in Git, commits do not belong to any
branch: each commit has metadata but that metadata do not record the name of
the branch (if any!) which was checked out at the time the commit was created
(on someone's computer).


```

## Loredana Tralli, 2024-09-04 13:59

Subject: Re: Ask for feature on git
Message-ID: <CAEO06GKzQTfm9z8ODCAYdHsWwgfHau0kuFA7WFkVqkPHbsm_1g@mail.gmail.com>
URL: https://gitlist.dev/e/CAEO06GKzQTfm9z8ODCAYdHsWwgfHau0kuFA7WFkVqkPHbsm_1g%40mail.gmail.com
In-Reply-To: <20240903170438.nhcnojx6upsxsj6d@carbon>

```
Hello,
Thank you both for your answers.

I was wondering if exists a bash/cli command to find out from with
branch a created the new branch.
Usually we can see it with graph or something like in this answers
https://stackoverflow.com/questions/1057564/pretty-git-branch-graphs,
nand I'd like to know if there is a command through bash to check
directly "you created branch test from branch release".

Thanks in advance for your help,
Regards

Loredana Tralli

Il giorno mar 3 set 2024 alle ore 19:04 Konstantin Khomoutov
<kostix@bswap.ru> ha scritto:
>
> On 9/3/24 17:18, Loredana Tralli wrote:
>
> > Is it possible to have a git command to find out which is the parent branch?
>
> Please try to specify what you consider to be a "parent branch" in your
> workflow. The problem is that there are multiple things in Git which may match
> what you are asking for. Even better would be to try to explain your original
> problem you're struggling with - which made you want the feature being
> discussed.
>
> Still, please consider that in Git, commits do not belong to any
> branch: each commit has metadata but that metadata do not record the name of
> the branch (if any!) which was checked out at the time the commit was created
> (on someone's computer).
>

```

## Konstantin Khomoutov, 2024-09-04 14:55

Subject: Re: Ask for feature on git
Message-ID: <20240904145544.xi7rez4hvbfcx57l@carbon>
URL: https://gitlist.dev/e/20240904145544.xi7rez4hvbfcx57l%40carbon
In-Reply-To: <CAEO06GKzQTfm9z8ODCAYdHsWwgfHau0kuFA7WFkVqkPHbsm_1g@mail.gmail.com>

```
On Wed, Sep 04, 2024 at 03:59:33PM +0200, Loredana Tralli wrote:

[...]

> and I'd like to know if there is a command through bash to check
> directly "you created branch test from branch release".

This is quite possible: Git has a command, `git merge-base`, which can be used
to figure out the relation between two branches you're interested in.
In particular, a call

  $ git merge-base --fork-point test release

should print the SHA-1 name of the last commit both branches share with each
other (before their histories have diverged) and exits with status code 0.
Otherwise ("test" was not forked off "release") the command would print
nothing and exit with status code 1.

I would suggest to read [1] to get better understanding of what it does.

 1. https://www.git-scm.com/docs/git-merge-base


```
