Working with branches is a core part of using Git. Often you will want to clean up and remove local and/or remote branches. Below are examples of how to delete local and remote branches in Git.
Delete a Local Branch
git branch -d <branch-name>
git branch --delete <branch-name>
The results of these two commands are identical. These commands will delete a local branch if the branch has been merged into its upstream branch. If you want to delete a local branch that has not been merged into its upstream, you must force delete it (shown below).
Force Delete a Local Branch
git branch -D <branch-name>
git branch --delete --force <branch-name>
These commands will perform identical actions and force delete a local branch.
Delete a Remote Branch
git push origin :<branch-name>
git push origin --delete <branch-name>
The results of these two commands are identical and delete a branch from a remote repository (like GitHub).
#create new branch "my-branch"
git branch my-branch
#push branch to remote repo
git push origin my-branch
#delete local branch
git branch -d my-branch
#delete remote branch
git push origin :my-branch