December 15, 2022How do I delete a Git branch locally and remotelyTo delete the remote branch:git push -d origin <branch-name>Orgit push origin :<branch-name> Executive Summarygit push -d <remote_name> <branchname> git branch -d <branchname> Note: In most cases, <remote_name> will be origin.Delete Local BranchTo delete the local branch use one of the following:git branch -d <branch_name> git branch -D <branch_name> The -d option is an alias for --delete, which only deletes the branch if it has already been fully merged in its upstream branch.The -D option is an alias for --delete --force, which deletes the branch “irrespective of its merged status.” [Source: man git-branch]As of Git v2.3, git branch -d (delete) learned to honor the -f (force) flag.You will receive an error if you try to delete the currently selected branch.Delete Remote BranchAs of Git v1.7.0, you can delete a remote branch using$ git push <remote_name> --delete <branch_name> which might be easier to remember that$ git push <remote_name> :<branch_name> which was added in Git v1.5.0 “to delete a remote branch or a tag.”Starting with Git v2.8.0, you can also use git push with the -d option as an alias for --delete. Therefore, the version of Git you have installed will dictate whether you need to use the easier or harder syntax. Like this:Like Loading...Related Git gitgithubhow to delete git branchlocalremote