{"thread":{"id":"53428","subject":"check if one branch contains another branch","startedAt":"2020-05-07T22:59:32Z","lastAt":"2020-05-08T12:07:55Z","messageCount":12,"participants":["Alexander Mills","Junio C Hamano","brian m. carlson","Randall S. Becker"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"397367","messageId":"CA+KyZp7TELrswPjNgB99BXXHEXi5pRr5bO3g_wy7zBvv1R4Kww@mail.gmail.com","threadId":"53428","inReplyTo":null,"subject":"check if one branch contains another branch","fromName":"Alexander Mills","fromEmail":"alexander.d.mills@gmail.com","sentAt":"2020-05-07T22:59:16Z","receivedAt":"2020-05-07T22:59:32Z","isPatch":false,"sender":{"key":"alexander.d.mills@gmail.com","avatar":"https://gravatar.com/avatar/8accf19b85aa1020f85582e1f001860f853ce55767c226545a0825a2fcd99f04?d=mp&s=160"},"body":"I am looking for a command:\n\n1>  if branch x contains branch y\n\nright now all I can find is\n\n2> if current branch contains commit y\n\ncan someone please accomplish #1 ?\nCrazy hard to find an answer to #1 online.\nThe user case is to delete old local branches by comparing them with\nthe remote integration branch.\n\nmore info if needed:\nhttps://stackoverflow.com/questions/61669056/how-to-determine-if-integration-branch-contains-feature-branch\n\n-alex\n\n--\nAlexander D. Mills\nNew cell phone # (415)730-1805\nlinkedin.com/in/alexanderdmills\n"},{"id":"397370","messageId":"xmqq1rnv2vi2.fsf@gitster.c.googlers.com","threadId":"53428","inReplyTo":"CA+KyZp7TELrswPjNgB99BXXHEXi5pRr5bO3g_wy7zBvv1R4Kww@mail.gmail.com","subject":"Re: check if one branch contains another branch","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2020-05-07T23:08:53Z","receivedAt":"2020-05-07T23:08:56Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Alexander Mills <alexander.d.mills@gmail.com> writes:\n\n> I am looking for a command:\n>\n> 1>  if branch x contains branch y\n>\n> right now all I can find is\n>\n> 2> if current branch contains commit y\n>\n> can someone please accomplish #1 ?\n\nStudy \"git merge-base --is-ancestor\" perhaps?\n"},{"id":"397371","messageId":"CA+KyZp6pvqqNnOOj0ap9ekPdv9mZg2u_NQuwFgMXfwfV17SrYQ@mail.gmail.com","threadId":"53428","inReplyTo":"xmqq1rnv2vi2.fsf@gitster.c.googlers.com","subject":"Re: check if one branch contains another branch","fromName":"Alexander Mills","fromEmail":"alexander.d.mills@gmail.com","sentAt":"2020-05-07T23:12:09Z","receivedAt":"2020-05-07T23:12:24Z","isPatch":false,"sender":{"key":"alexander.d.mills@gmail.com","avatar":"https://gravatar.com/avatar/8accf19b85aa1020f85582e1f001860f853ce55767c226545a0825a2fcd99f04?d=mp&s=160"},"body":"so it would be:\n\nfeature_branch='my_branch'  # the branch that I want to ensure is\ncompletely merged into origin/dev\ngit merge-base  origin/dev --is-ancestor \"$feature_branch\"\n\nthat won't work?  since git merge-base only works with current branch?\n\nOn Thu, May 7, 2020 at 4:08 PM Junio C Hamano <gitster@pobox.com> wrote:\n>\n> Alexander Mills <alexander.d.mills@gmail.com> writes:\n>\n> > I am looking for a command:\n> >\n> > 1>  if branch x contains branch y\n> >\n> > right now all I can find is\n> >\n> > 2> if current branch contains commit y\n> >\n> > can someone please accomplish #1 ?\n>\n> Study \"git merge-base --is-ancestor\" perhaps?\n\n\n\n-- \nAlexander D. Mills\nNew cell phone # (415)730-1805\nlinkedin.com/in/alexanderdmills\n"},{"id":"397372","messageId":"CA+KyZp6CBJse9jRYowgkaRctuRU4mnFz3TVwkKTwkZWkjj3GTA@mail.gmail.com","threadId":"53428","inReplyTo":"CA+KyZp6pvqqNnOOj0ap9ekPdv9mZg2u_NQuwFgMXfwfV17SrYQ@mail.gmail.com","subject":"Re: check if one branch contains another branch","fromName":"Alexander Mills","fromEmail":"alexander.d.mills@gmail.com","sentAt":"2020-05-07T23:15:12Z","receivedAt":"2020-05-07T23:15:29Z","isPatch":false,"sender":{"key":"alexander.d.mills@gmail.com","avatar":"https://gravatar.com/avatar/8accf19b85aa1020f85582e1f001860f853ce55767c226545a0825a2fcd99f04?d=mp&s=160"},"body":"I tried this:\n\ngit checkout origin/dev\n# now in detached head state\ngit branch --contains \"$(git rev-parse \"$feature_branch\")\"\n\nand I got this output:\n<name of feature branch>\n\nnot sure what that means\n\nOn Thu, May 7, 2020 at 4:12 PM Alexander Mills\n<alexander.d.mills@gmail.com> wrote:\n>\n> so it would be:\n>\n> feature_branch='my_branch'  # the branch that I want to ensure is\n> completely merged into origin/dev\n> git merge-base  origin/dev --is-ancestor \"$feature_branch\"\n>\n> that won't work?  since git merge-base only works with current branch?\n>\n> On Thu, May 7, 2020 at 4:08 PM Junio C Hamano <gitster@pobox.com> wrote:\n> >\n> > Alexander Mills <alexander.d.mills@gmail.com> writes:\n> >\n> > > I am looking for a command:\n> > >\n> > > 1>  if branch x contains branch y\n> > >\n> > > right now all I can find is\n> > >\n> > > 2> if current branch contains commit y\n> > >\n> > > can someone please accomplish #1 ?\n> >\n> > Study \"git merge-base --is-ancestor\" perhaps?\n>\n>\n>\n> --\n> Alexander D. Mills\n> New cell phone # (415)730-1805\n> linkedin.com/in/alexanderdmills\n\n\n\n-- \nAlexander D. Mills\nNew cell phone # (415)730-1805\nlinkedin.com/in/alexanderdmills\n"},{"id":"397373","messageId":"20200507232448.GB7234@camp.crustytoothpaste.net","threadId":"53428","inReplyTo":"CA+KyZp6pvqqNnOOj0ap9ekPdv9mZg2u_NQuwFgMXfwfV17SrYQ@mail.gmail.com","subject":"Re: check if one branch contains another branch","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2020-05-07T23:24:48Z","receivedAt":"2020-05-07T23:25:26Z","isPatch":false,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"On 2020-05-07 at 23:12:09, Alexander Mills wrote:\n> so it would be:\n> \n> feature_branch='my_branch'  # the branch that I want to ensure is\n> completely merged into origin/dev\n> git merge-base  origin/dev --is-ancestor \"$feature_branch\"\n> \n> that won't work?  since git merge-base only works with current branch?\n\nNo, that's not the case.  You can write this:\n\n  git merge-base --is-ancestor $feature_branch origin/dev\n\nThis works from any branch and exits 0 if the branch is in origin/dev\nand 1 if it is not.  In neither case does it print anything.\n-- \nbrian m. carlson: Houston, Texas, US\nOpenPGP: https://keybase.io/bk2204\n"},{"id":"397374","messageId":"CA+KyZp4keGp8j0rzCtr0fEogZqkKwTNLvRBZ2QOUzjStP+V2uA@mail.gmail.com","threadId":"53428","inReplyTo":"20200507232448.GB7234@camp.crustytoothpaste.net","subject":"Re: check if one branch contains another branch","fromName":"Alexander Mills","fromEmail":"alexander.d.mills@gmail.com","sentAt":"2020-05-07T23:28:40Z","receivedAt":"2020-05-07T23:28:55Z","isPatch":false,"sender":{"key":"alexander.d.mills@gmail.com","avatar":"https://gravatar.com/avatar/8accf19b85aa1020f85582e1f001860f853ce55767c226545a0825a2fcd99f04?d=mp&s=160"},"body":"Thanks will check that out.\n\nThis command does not seem to work :(\n\n> git branch --contains branchB\n\nI do this:\n\ngit checkout branchB\ngit commit --allow-empty -am 'empty commit message'\ngit checkout dev\ngit branch --contains branchB  ==> exit code 0\ngit branch --contains $(git rev-parse branchB)  ==> exit code 0\n\nthis seems like a bug or something.  Why wouldn't it exit with 1,\nsince it obviously does not contain that commit?\nThis kinda sucks tbh :(\n\n\n\n\n\nOn Thu, May 7, 2020 at 4:25 PM brian m. carlson\n<sandals@crustytoothpaste.net> wrote:\n>\n> On 2020-05-07 at 23:12:09, Alexander Mills wrote:\n> > so it would be:\n> >\n> > feature_branch='my_branch'  # the branch that I want to ensure is\n> > completely merged into origin/dev\n> > git merge-base  origin/dev --is-ancestor \"$feature_branch\"\n> >\n> > that won't work?  since git merge-base only works with current branch?\n>\n> No, that's not the case.  You can write this:\n>\n>   git merge-base --is-ancestor $feature_branch origin/dev\n>\n> This works from any branch and exits 0 if the branch is in origin/dev\n> and 1 if it is not.  In neither case does it print anything.\n> --\n> brian m. carlson: Houston, Texas, US\n> OpenPGP: https://keybase.io/bk2204\n\n\n\n-- \nAlexander D. Mills\nNew cell phone # (415)730-1805\nlinkedin.com/in/alexanderdmills\n"},{"id":"397375","messageId":"06da01d624c7$acb17090$061451b0$@nexbridge.com","threadId":"53428","inReplyTo":"CA+KyZp7TELrswPjNgB99BXXHEXi5pRr5bO3g_wy7zBvv1R4Kww@mail.gmail.com","subject":"RE: check if one branch contains another branch","fromName":"Randall S. Becker","fromEmail":"rsbecker@nexbridge.com","sentAt":"2020-05-07T23:31:40Z","receivedAt":"2020-05-07T23:31:52Z","isPatch":false,"sender":{"key":"randall.becker@nexbridge.ca","avatar":"https://avatars.githubusercontent.com/u/28956764?v=4"},"body":"On May 7, 2020 6:59 PM Alexander Mills, Wrote:\n> To: git@vger.kernel.org\n> Subject: check if one branch contains another branch\n> \n> I am looking for a command:\n> \n> 1>  if branch x contains branch y\n> \n> right now all I can find is\n> \n> 2> if current branch contains commit y\n> \n> can someone please accomplish #1 ?\n> Crazy hard to find an answer to #1 online.\n> The user case is to delete old local branches by comparing them with the\n> remote integration branch.\n> \n> more info if needed:\n> https://stackoverflow.com/questions/61669056/how-to-determine-if-\n> integration-branch-contains-feature-branch\n\nLooking 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.\n\nA 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.\n\nIt is a different way of looking at the problem, but IMHO, a more representative way when taking developers and deployment into account.\n\nRegards,\nRandall\n\n"},{"id":"397377","messageId":"CA+KyZp7Ur3kW3qrCe3hOz16gA9y_B7rSGin62=eKMjCCqLsR4w@mail.gmail.com","threadId":"53428","inReplyTo":"06da01d624c7$acb17090$061451b0$@nexbridge.com","subject":"Re: check if one branch contains another branch","fromName":"Alexander Mills","fromEmail":"alexander.d.mills@gmail.com","sentAt":"2020-05-07T23:37:34Z","receivedAt":"2020-05-07T23:37:49Z","isPatch":false,"sender":{"key":"alexander.d.mills@gmail.com","avatar":"https://gravatar.com/avatar/8accf19b85aa1020f85582e1f001860f853ce55767c226545a0825a2fcd99f04?d=mp&s=160"},"body":"I assume that:\n\ngit branch -d  xxx\n\nwill prevent a delete if the current branch doesn't contain xxx..\nI don't want to have to checkout  origin/dev in order to run that command,\nthat's one part of the problem\n\n\nOn Thu, May 7, 2020 at 4:31 PM Randall S. Becker <rsbecker@nexbridge.com> wrote:\n>\n> On May 7, 2020 6:59 PM Alexander Mills, Wrote:\n> > To: git@vger.kernel.org\n> > Subject: check if one branch contains another branch\n> >\n> > I am looking for a command:\n> >\n> > 1>  if branch x contains branch y\n> >\n> > right now all I can find is\n> >\n> > 2> if current branch contains commit y\n> >\n> > can someone please accomplish #1 ?\n> > Crazy hard to find an answer to #1 online.\n> > The user case is to delete old local branches by comparing them with the\n> > remote integration branch.\n> >\n> > more info if needed:\n> > https://stackoverflow.com/questions/61669056/how-to-determine-if-\n> > integration-branch-contains-feature-branch\n>\n> 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.\n>\n> 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.\n>\n> It is a different way of looking at the problem, but IMHO, a more representative way when taking developers and deployment into account.\n>\n> Regards,\n> Randall\n>\n\n\n-- \nAlexander D. Mills\nNew cell phone # (415)730-1805\nlinkedin.com/in/alexanderdmills\n"},{"id":"397378","messageId":"xmqqwo5n1fej.fsf@gitster.c.googlers.com","threadId":"53428","inReplyTo":"CA+KyZp7Ur3kW3qrCe3hOz16gA9y_B7rSGin62=eKMjCCqLsR4w@mail.gmail.com","subject":"Re: check if one branch contains another branch","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2020-05-07T23:41:56Z","receivedAt":"2020-05-07T23:42:00Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Alexander Mills <alexander.d.mills@gmail.com> writes:\n\n> I assume that:\n>\n> git branch -d  xxx\n>\n> will prevent a delete if the current branch doesn't contain xxx..\n> I don't want to have to checkout  origin/dev in order to run that command,\n> that's one part of the problem\n\nIn that case, don't you want to learn, not just if your 'dev' has\nanything that is not merged/accepted by origin/dev, what commits\nin 'dev' are not yet merged in origin/dev?\n\n $ git log origin/dev..dev\n\nwould show them.\n\n"},{"id":"397379","messageId":"20200507234718.GC7234@camp.crustytoothpaste.net","threadId":"53428","inReplyTo":"CA+KyZp4keGp8j0rzCtr0fEogZqkKwTNLvRBZ2QOUzjStP+V2uA@mail.gmail.com","subject":"Re: check if one branch contains another branch","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2020-05-07T23:47:18Z","receivedAt":"2020-05-07T23:47:26Z","isPatch":false,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"On 2020-05-07 at 23:28:40, Alexander Mills wrote:\n> Thanks will check that out.\n> \n> This command does not seem to work :(\n> \n> > git branch --contains branchB\n> \n> I do this:\n> \n> git checkout branchB\n> git commit --allow-empty -am 'empty commit message'\n> git checkout dev\n> git branch --contains branchB  ==> exit code 0\n> git branch --contains $(git rev-parse branchB)  ==> exit code 0\n> \n> this seems like a bug or something.  Why wouldn't it exit with 1,\n> since it obviously does not contain that commit?\n\nBecause that command operates differently.  From git-branch(1):\n\n  With --contains, shows only the branches that contain the named commit\n  (in other words, the branches whose tip commits are descendants of the\n  named commit)…..\n\ngit branch --contains branchB prints only branchB, because no other\nbranch contains it.  In other words, this asks to list the branches\nwhich contain the specified commit, and as long as it has done so\nsuccessfully (even if that answer is \"none of them\"), it exits 0.  The\ncurrent branch has no effect on it because it's listing branches which\nmatch a criterion, not comparing the specified revision to the current\nbranch.\n\nNote that this is not a porcelain command (that is, it is not intended\nfor scripting) and need not be especially performant.  git merge-base\n--is-ancestor is the better way if you want to script things or get a\nmore performant answer because it does less work, especially if there\nare many branches.\n\n> This kinda sucks tbh :(\n\nCertainly it fails to do the thing you wanted to do with it, but since\nthat isn't what it's documented to do, I don't see that as a particular\nproblem.\n\nIs the documentation unclear in some way or could it be more helpful?\nIf so, please tell us so we can improve it.\n-- \nbrian m. carlson: Houston, Texas, US\nOpenPGP: https://keybase.io/bk2204\n"},{"id":"397385","messageId":"CA+KyZp7emY12sy6QdGBJ5T9e135VCfjeqTy9u_FWh+FA1d-uFg@mail.gmail.com","threadId":"53428","inReplyTo":"CA+KyZp7Ur3kW3qrCe3hOz16gA9y_B7rSGin62=eKMjCCqLsR4w@mail.gmail.com","subject":"Re: check if one branch contains another branch","fromName":"Alexander Mills","fromEmail":"alexander.d.mills@gmail.com","sentAt":"2020-05-08T01:01:04Z","receivedAt":"2020-05-08T01:01:22Z","isPatch":false,"sender":{"key":"alexander.d.mills@gmail.com","avatar":"https://gravatar.com/avatar/8accf19b85aa1020f85582e1f001860f853ce55767c226545a0825a2fcd99f04?d=mp&s=160"},"body":"git branch -d foo   # safe delete\n\nthe above doesn't seem to work if you squash commits into an\nintegration branch, I will get something like:\n\n========================================================\n git branch -d CP-10-master\nwarning: deleting branch 'CP-10-master' that has been merged to\n         'refs/remotes/origin/CP-10-master', but not yet merged to HEAD.\nDeleted branch CP-10-master (was faeb801).\n==========================================================\n\n\nIf a branch gets squashed into another, how does merge-base do it's\nthing, since it's not a fast-forward merge etc?\nI assume that it's not possible, for example this script shows that if\n git merge --squash is used, git doesn't know that the unsquashed\nbranch is already merged:\n\n==========================================================\n\n#!/bin/bash\n\nset -e\n\ngit checkout master\ngit branch -D delete-me-1 || echo\ngit branch -D delete-me-2 || echo\n\ngit checkout -b delete-me-1\ngit checkout -b delete-me-2\ngit commit --allow-empty -am \"first new one\"\ngit commit --allow-empty -am \"second new one\"\ngit commit --allow-empty -am \"third new one\"\ngit checkout delete-me-1\ngit merge --squash delete-me-2  ### compare without squash\n\nif git merge-base --is-ancestor delete-me-2 delete-me-1; then\n  echo 'delete-me-1 is an ancestor of delete-me-2'\nelse\n  echo 'not an ancestor'\nfi\n========================================================\n\nthat will print \"not an ancestor\" if  --squash is used..\n\n-alex\n\n\n\n\nOn Thu, May 7, 2020 at 4:37 PM Alexander Mills\n<alexander.d.mills@gmail.com> wrote:\n>\n> I assume that:\n>\n> git branch -d  xxx\n>\n> will prevent a delete if the current branch doesn't contain xxx..\n> I don't want to have to checkout  origin/dev in order to run that command,\n> that's one part of the problem\n>\n>\n> On Thu, May 7, 2020 at 4:31 PM Randall S. Becker <rsbecker@nexbridge.com> wrote:\n> >\n> > On May 7, 2020 6:59 PM Alexander Mills, Wrote:\n> > > To: git@vger.kernel.org\n> > > Subject: check if one branch contains another branch\n> > >\n> > > I am looking for a command:\n> > >\n> > > 1>  if branch x contains branch y\n> > >\n> > > right now all I can find is\n> > >\n> > > 2> if current branch contains commit y\n> > >\n> > > can someone please accomplish #1 ?\n> > > Crazy hard to find an answer to #1 online.\n> > > The user case is to delete old local branches by comparing them with the\n> > > remote integration branch.\n> > >\n> > > more info if needed:\n> > > https://stackoverflow.com/questions/61669056/how-to-determine-if-\n> > > integration-branch-contains-feature-branch\n> >\n> > 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.\n> >\n> > 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.\n> >\n> > It is a different way of looking at the problem, but IMHO, a more representative way when taking developers and deployment into account.\n> >\n> > Regards,\n> > Randall\n> >\n>\n>\n> --\n> Alexander D. Mills\n> New cell phone # (415)730-1805\n> linkedin.com/in/alexanderdmills\n\n\n\n--\nAlexander D. Mills\nNew cell phone # (415)730-1805\nlinkedin.com/in/alexanderdmills\n"},{"id":"397399","messageId":"070601d62531$4a95ba00$dfc12e00$@nexbridge.com","threadId":"53428","inReplyTo":"CA+KyZp7emY12sy6QdGBJ5T9e135VCfjeqTy9u_FWh+FA1d-uFg@mail.gmail.com","subject":"RE: check if one branch contains another branch","fromName":"Randall S. Becker","fromEmail":"rsbecker@nexbridge.com","sentAt":"2020-05-08T12:07:43Z","receivedAt":"2020-05-08T12:07:55Z","isPatch":false,"sender":{"key":"randall.becker@nexbridge.ca","avatar":"https://avatars.githubusercontent.com/u/28956764?v=4"},"body":"On May 7, 2020 9:01 PM, Alexander Mills Wrote:\n> git branch -d foo   # safe delete\n> \n> the above doesn't seem to work if you squash commits into an integration\n> branch, I will get something like:\n> \n> ========================================================\n>  git branch -d CP-10-master\n> warning: deleting branch 'CP-10-master' that has been merged to\n>          'refs/remotes/origin/CP-10-master', but not yet merged to HEAD.\n> Deleted branch CP-10-master (was faeb801).\n> ==========================================================\n> \n> \n> If a branch gets squashed into another, how does merge-base do it's thing,\n> since it's not a fast-forward merge etc?\n> I assume that it's not possible, for example this script shows that if  git merge\n> --squash is used, git doesn't know that the unsquashed branch is already\n> merged:\n> \n\nCorrect. That is what I pointed out in my first response.\n\n> ==========================================================\n> \n> #!/bin/bash\n> \n> set -e\n> \n> git checkout master\n> git branch -D delete-me-1 || echo\n> git branch -D delete-me-2 || echo\n> \n> git checkout -b delete-me-1\n> git checkout -b delete-me-2\n> git commit --allow-empty -am \"first new one\"\n> git commit --allow-empty -am \"second new one\"\n> git commit --allow-empty -am \"third new one\"\n> git checkout delete-me-1\n> git merge --squash delete-me-2  ### compare without squash\n> \n> if git merge-base --is-ancestor delete-me-2 delete-me-1; then\n>   echo 'delete-me-1 is an ancestor of delete-me-2'\n> else\n>   echo 'not an ancestor'\n> fi\n> ========================================================\n> \n> that will print \"not an ancestor\" if  --squash is used..\n\nAlso correct.\n\n> \n> -alex\n> \n> \n> \n> \n> On Thu, May 7, 2020 at 4:37 PM Alexander Mills\n> <alexander.d.mills@gmail.com> wrote:\n> >\n> > I assume that:\n> >\n> > git branch -d  xxx\n> >\n> > will prevent a delete if the current branch doesn't contain xxx..\n> > I don't want to have to checkout  origin/dev in order to run that\n> > command, that's one part of the problem\n> >\n> >\n> > On Thu, May 7, 2020 at 4:31 PM Randall S. Becker\n> <rsbecker@nexbridge.com> wrote:\n> > >\n> > > On May 7, 2020 6:59 PM Alexander Mills, Wrote:\n> > > > To: git@vger.kernel.org\n> > > > Subject: check if one branch contains another branch\n> > > >\n> > > > I am looking for a command:\n> > > >\n> > > > 1>  if branch x contains branch y\n> > > >\n> > > > right now all I can find is\n> > > >\n> > > > 2> if current branch contains commit y\n> > > >\n> > > > can someone please accomplish #1 ?\n> > > > Crazy hard to find an answer to #1 online.\n> > > > The user case is to delete old local branches by comparing them\n> > > > with the remote integration branch.\n> > > >\n> > > > more info if needed:\n> > > > https://stackoverflow.com/questions/61669056/how-to-determine-if-\n> > > > integration-branch-contains-feature-branch\n> > >\n> > > Looking at this slightly differently, if you try to delete a branch, git branch\n> -d feature-branch, and the branch has not been merged, then the delete will\n> fail. A simple way of looking at it is if the HEAD of the branch has no\n> successor commits then it is not merged (not 100% decisive, but git branch -d\n> is). It is not really that a branch has been merged, but that a commit has\n> successors, meaning that it has been merged. However, unless you are using\n> GitLab, a git merge --squash will not answer your question even if the branch\n> was merged.\n> > >\n> > > A better way of looking at this is in terms of Pull (GitHub, BitBucket) or\n> Merge (GitLab) requests. Has there been a Pull Request for a branch and has\n> the branch been closed? Meaning that when you do a git fetch --prune, your\n> merged/deleted branches go away unless you are on that branch. Looking at\n> the Pull Request history is much more useful in determining whether a branch\n> has been integrated into a main development branch or production branch in\n> a GitFlow process.\n> > >\n> > > It is a different way of looking at the problem, but IMHO, a more\n> representative way when taking developers and deployment into account.\n\nAs I indicated, this may be more appropriate to do what you want to do on the upstream enterprise git server rather than on your local clone.\n\n"}]}