Reputation: 11
We usually delete the branch that has been worked on after it has been merged after a pull request - is there a way we can set this to happen by default so it automatically deletes the branch once a PR is approved and merged?
Upvotes: 1
Views: 1634
Reputation: 1324148
Yes, it is. Since August 2019 only.
As announced on Twitter here and here by Harry Marr, co-founder of Dependabot, which is now part of Github:
You know how you merge a pull request then sit there a few seconds for it to do its thing, then click to delete the branch… well… you don’t have to do that any more!
See "Managing the automatic deletion of branches"
A git remote prune origin
, as mentioned in Kleskowy's answer, is still needed locally though.
Upvotes: 0
Reputation: 2668
I don't think this is available in GitHub, there are open requests for this function to happen:
In BitBucket however, there is this feature called "Close branch after Pull Request merge", see the docs
However - regardless of deleting the branch in the remote repository, you and your fellow developers would still need to delete the local branches tracking the (deleted) remote branch. You can do this (for all branches) by running:
$ git remote prune [--dry-run] origin
Above command removes local branches that are stale (usually - there's no upstream branch on the remote any more). Use it with caution after reading the Git docs.
Upvotes: 1