git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: check if one branch contains another branch

From
Alexander Mills <alexander.d.mills@gmail.com>
Date
May 7, 2020, 23:37 UTC
Message-ID
<CA+KyZp7Ur3kW3qrCe3hOz16gA9y_B7rSGin62=eKMjCCqLsR4w@mail.gmail.com>
In-Reply-To
<06da01d624c7$acb17090$061451b0$@nexbridge.com>
I assume that:
git branch -d  xxx

will prevent a delete if the current branch doesn't contain xxx.. I don't want to have to checkout origin/dev in order to run that command, that's one part of the problem

On Thu, May 7, 2020 at 4:31 PM Randall S. Becker <rsbecker@nexbridge.com> wrote:
Show 31 quoted lines
>
> On May 7, 2020 6:59 PM Alexander Mills, Wrote:
> > To: git@vger.kernel.org
> > Subject: check if one branch contains another branch
> >
> > I am looking for a command:
> >
> > 1>  if branch x contains branch y
> >
> > right now all I can find is
> >
> > 2> if current branch contains commit y
> >
> > can someone please accomplish #1 ?
> > Crazy hard to find an answer to #1 online.
> > The user case is to delete old local branches by comparing them with the
> > remote integration branch.
> >
> > more info if needed:
> > https://stackoverflow.com/questions/61669056/how-to-determine-if-
> > integration-branch-contains-feature-branch
>
> Looking at this slightly differently, if you try to delete a branch, git branch -d feature-branch, and the branch has not been merged, then the delete will fail. A simple way of looking at it is if the HEAD of the branch has no successor commits then it is not merged (not 100% decisive, but git branch -d is). It is not really that a branch has been merged, but that a commit has successors, meaning that it has been merged. However, unless you are using GitLab, a git merge --squash will not answer your question even if the branch was merged.
>
> A better way of looking at this is in terms of Pull (GitHub, BitBucket) or Merge (GitLab) requests. Has there been a Pull Request for a branch and has the branch been closed? Meaning that when you do a git fetch --prune, your merged/deleted branches go away unless you are on that branch. Looking at the Pull Request history is much more useful in determining whether a branch has been integrated into a main development branch or production branch in a GitFlow process.
>
> It is a different way of looking at the problem, but IMHO, a more representative way when taking developers and deployment into account.
>
> Regards,
> Randall
>
-- 
Alexander D. Mills
New cell phone # (415)730-1805
linkedin.com/in/alexanderdmills
Previous: Randall S. BeckerNext: Junio C Hamano
Message 9 of 12 in “check if one branch contains another branch”
  1. Alexander MillsMay 7, 2020
  2. Junio C HamanoMay 7, 2020
  3. Alexander MillsMay 7, 2020
  4. Alexander MillsMay 7, 2020
  5. brian m. carlsonMay 7, 2020
  6. Alexander MillsMay 7, 2020
  7. brian m. carlsonMay 7, 2020
  8. Randall S. BeckerMay 7, 2020
  9. Alexander MillsMay 7, 2020
  10. Junio C HamanoMay 7, 2020
  11. Alexander MillsMay 8, 2020
  12. Randall S. BeckerMay 8, 2020

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.