How to delete a Git branch both locally and remotely

Delete Local branch

To delete the local branch use the following command.

git branch -d <branch_name>
or
git branch --delete <branch_name>

Delete the Remote branch

There are couple of ways to delete a remote git branch.
As of git v1.7 you can use the following command, which is more easier to remember to delete a remote branch.


git push origin --delete <branch_name>

The older way of doing it was;
 
git push origin :<branch_name>

After deleting the remote branch, you should run the following command in other machines which uses the same git repository to propagate the changes.


git fetch --all --prune

Comments