Suggest an editImprove this articleRefine the answer for “How to delete a branch?”. Your changes go to moderation before they’re published.Approval requiredContentWhat you’re changing🇺🇸EN🇺🇦UAPreviewTitle (EN)Short answer (EN)In **Git**, a branch can be deleted locally and in the remote repository, and these are different operations. **Key point:** locally it is `git branch -d` / `git branch -D`, remotely it is `git push origin --delete <branch>`.Shown above the full answer for quick recall.Answer (EN)ImageIn **Git**, a branch can be deleted **locally** and **in the remote repository**. These are different operations. --- ## Deleting a local branch ### Safe deletion (recommended) ```bash git branch -d feature/my-feature ``` - deletes the branch **only if it has already been merged**; - protects against losing changes. ### Force deletion ```bash git branch -D feature/my-feature ``` - deletes the branch **even if it has not been merged**; - used when the branch is no longer needed. --- ## Deleting a remote branch ```bash git push origin --delete feature/my-feature ``` Deletes the branch in the remote repository (`origin`). --- ## Cleaning up references to deleted branches If a branch has already been deleted on the server but is still shown locally: ```bash git fetch --prune ``` --- ## Important points - Deleting a branch **does not delete commits** if other references point to them. - You cannot delete the branch **you are currently on** - you must switch first. - Feature branches are usually deleted **after being merged into the main branch**. --- ## Summary - Locally: `git branch -d` / `git branch -D` - Remotely: `git push origin --delete <branch>`For the reviewerNote to the moderator (optional)Visible only to the moderator. Helps review go faster.