threads / discuss / 62042

Ask for feature on git

Subject: Ask for feature on git

## tl;dr

5 messages between Sep 3, 2024 and Sep 4, 2024.

replies: 4people: 3as markdown or json

Loredana Tralli· Sep 3, 2024, 08:18 UTC · lore

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· Sep 3, 2024, 13:33 UTC · re: Loredana Tralli · lore

Re: Ask for feature on git

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· Sep 3, 2024, 17:04 UTC · re: Loredana Tralli · lore

Re: Ask for feature on git

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· Sep 4, 2024, 13:59 UTC · re: Konstantin Khomoutov · lore

Re: Ask for feature on git

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:

Show 16 quoted lines
>
> 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· Sep 4, 2024, 14:55 UTC · re: Loredana Tralli · lore

Re: Ask for feature on git

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

← back to recent threads