However I still like to delete the branch. git push remoteName :branchNameĮven if the branch is never merged, typically I would still like to keep the commits around for posterity. I use the web interface, but the equivalent command is below. Then I delete the remote tracking branch git branch -dr remoteName\branchName This prevents it from being accidentally pushed later. These branches also get propagated to all of the repository's forks.įirst I delete my local branch. This prevents the visual clutter of a long list of branches in your repository. I prefer to delete branches after they're merged in. This is why I change my links to point to a commit or tag after I delete a branch on GitHub.īecause some links can't be changed, such as in email, I now avoid hyperlinking to GitHub branches entirely and link to a commit or tag from day one. You'll get a 404 Not Found error for those links. I would add that the disadvantage of deleting branches is that you will break any hyperlinks to those branches on GitHub (this question is tagged github). should not, you'll always have the hotfixes alive until they are integrated in a future version. Tagging is also the key to solve your original problem: if you establish that any branch merged to the "work" branches can and should be deleted, and that any one that is merged to a version tag, "production", etc. Of course no history management (pull requests or otherwise) replaces proper tagging of versions (which you preferably automate with the same tool/script that deploys/packages a version), so you can always fast-switch to whatever your users happen to be on at a given moment.
Delete branch git full#
My current work team, for example, prunes all branches that are not master or deployment-related (e.g., production, staging, etc.) as soon as their pull requests gets merged, and we still have full tracking of how the related commits formed each incremental improvement of each product.
This is so commonplace that recently Github added a (sweet) feature that pops a "delete branch" button right after you merge a pull request.īut it is worth noticing that each group should adopt the workflow that suits it best (and it may or may not lead to deleting such branches).
Delete branch git code#
Since the question has the "github" tag, I'd also add this: specifically in Github, if you pull-request a branch and it gets merged (either via the UI or by merging the pull request's branch), you won't lose the pull request data (including comments), even if you remove the branch.Ī consequence of this: If you incorporate pull requests as a part of your workflow (which blends sweetly with code reviews), you can safely delete branches as soon as they get merged.