Delete git branch from local and remote

Github provides different options to delete unwanted branches on your git terminal or from remote github repository.

Delete a branch from your local git terminal.

Use a simple --delete option to delete a branch from your local git.

git branch --delete <branch_name>

This will not delete a branch if you have a commit or any work in progress. To delete it forcefully, use -D with the branch name.

git branch -D <branch_name>

You can also delete multiple branches from your local git by specifying all the names in a single command.

git branch -D <branch1> <branch2>...

Use regex in the command to delete the branches having similar names -

git branch -D `git branch | grep -E 'branch-*'`

The above command deletes all the branch starting with the word "branch-".

Delete a branch from remote.

From the terminal, use the below command to delete the branch from your Github repository.

git push <remote_name> --delete <branch_name>

Similarly, use different names to delete multiple branches from your Github repository.

git push <remote_name> --delete <branch1> <branch2>