{"thread":{"id":"45624","subject":"Git branch deletion not based on HEAD branch anymore","startedAt":"2017-04-06T20:32:22Z","lastAt":"2017-04-07T11:18:01Z","messageCount":3,"participants":["Javier Domingo Cansino","Jeff King"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"316302","messageId":"CALZVapk4zxn-DSdMdy2q-Z0KvsBvx4MCSB5UDVOaBrBvAqw_AA@mail.gmail.com","threadId":"45624","inReplyTo":null,"subject":"Git branch deletion not based on HEAD branch anymore","fromName":"Javier Domingo Cansino","fromEmail":"javierdo1@gmail.com","sentAt":"2017-04-06T20:31:55Z","receivedAt":"2017-04-06T20:32:22Z","isPatch":false,"sender":{"key":"javierdo1@gmail.com","avatar":"https://gravatar.com/avatar/0f43d4d2e5f4320e8b5e1a46914213c5459dd0de261ab1587f222827f863d727?d=mp&s=160"},"body":"Hello,\n\nI have noticed that in the \"latest\" versions of git, `git branch -d\nbranch` instead of refusing to delete a branch that hasn't been merged\nto HEAD, it now throws a warning and deleting the local branch if it's\npresent in a remote.\n\nExample:\n```\n> git branch -d command-runner\nwarning: deleting branch 'command-runner' that has been merged to\n         'refs/remotes/origin/command-runner', but not yet merged to HEAD.\nDeleted branch command-runner (was 1716ed5).\n```\n\nAfter diving in git blame for a while I have realized that \"lately\"\nrefers to a commit done in 2009.\n\nBecause the change is over 7 years old, I will explain what is my use case.\n\nThe workflow I follow since I started with git is to start an exact\nreplica of my working environment in a personal fork. Anything deleted\nlocally is deleted remotely and viceversa. This allows me to move\nbetween work and home smoothly. I also use the default `git config\npush.default matching`\n\nMy typical day starts and ends pulling master from the central repo,\nand `git branch -d`-ing  all the branches I have in local. git would\ndelete the ones that have been merged, and leave alone the ones that\nhave been not been merged. Then I rebase all my branches and push the\nnew master and rebased branches. Because all my local branches track\nmy personal repo, all of them get deleted if I execute my scripts.\n\nI understand it's not possible / convenient anymore to go back, but\nwould it be possible to have an option such as `--merged` to support\nthe old usecase?\n\n-- \nJavier Domingo Cansino\n"},{"id":"316327","messageId":"20170407063808.frjjclz7ksqgmtyt@sigill.intra.peff.net","threadId":"45624","inReplyTo":"CALZVapk4zxn-DSdMdy2q-Z0KvsBvx4MCSB5UDVOaBrBvAqw_AA@mail.gmail.com","subject":"Re: Git branch deletion not based on HEAD branch anymore","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2017-04-07T06:38:08Z","receivedAt":"2017-04-07T06:38:16Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Thu, Apr 06, 2017 at 10:31:55PM +0200, Javier Domingo Cansino wrote:\n\n> I understand it's not possible / convenient anymore to go back, but\n> would it be possible to have an option such as `--merged` to support\n> the old usecase?\n\nThere's \"branch --merged\" already. And in recent versions of git, the\nscriptable for-each-ref knows it, too. So you could do something like:\n\n  git for-each-ref --format='delete %(refname)' --merged HEAD refs/heads/ |\n  grep -v 'any-branches-you-want-saved' |\n  git update-ref --stdin\n\nThe \"--merged\" option to git-branch is only used for listing. In theory\nwe could use it for selection in other operations, like \"git branch -d\n--merged\". But I'm not sure how you'd tell it _not_ to delete the branch\nthat matches HEAD.\n\n-Peff\n"},{"id":"316331","messageId":"CALZVapk1nhBv04QQSV9jOpg-KQxVE8wKgV9dgwm0m+J3fxsD3g@mail.gmail.com","threadId":"45624","inReplyTo":"20170407063808.frjjclz7ksqgmtyt@sigill.intra.peff.net","subject":"Re: Git branch deletion not based on HEAD branch anymore","fromName":"Javier Domingo Cansino","fromEmail":"javierdo1@gmail.com","sentAt":"2017-04-07T11:17:35Z","receivedAt":"2017-04-07T11:18:01Z","isPatch":false,"sender":{"key":"javierdo1@gmail.com","avatar":"https://gravatar.com/avatar/0f43d4d2e5f4320e8b5e1a46914213c5459dd0de261ab1587f222827f863d727?d=mp&s=160"},"body":"> There's \"branch --merged\" already. And in recent versions of git, the\n> scriptable for-each-ref knows it, too. So you could do something like:\n>\n>   git for-each-ref --format='delete %(refname)' --merged HEAD refs/heads/ |\n>   grep -v 'any-branches-you-want-saved' |\n>   git update-ref --stdin\n\nYeah I wanted to avoid anything else that git branch -d, as it doesn't\ndelete the currently checked out. I am not really familiar with\nplumbing commands.\n\n> The \"--merged\" option to git-branch is only used for listing. In theory\n> we could use it for selection in other operations, like \"git branch -d\n> --merged\". But I'm not sure how you'd tell it _not_ to delete the branch\n> that matches HEAD.\n\nLast time I checked git branch doesn't delete the currently checked\nout branch, does it?\n\nAdding the --merged to `git branch -d` would be awesome\n\nJavier\n"}]}