Step-by-Step: How to delete a git branch from local as well as remote origin

If you have a git branch that you have pushed upstream to the remote origin and want to delete both this local and the remote branch, you can follow the below two commands,

Step 1: Delete Git Local Branch

Make use of the git branch command with --delete flag,

git branch --delete <branch-name>

You can also make use of the shorthand version -d

git branch -d <branch-name>

If the branch is not merged then you would also need to make use of the --force or -f flag.

git branch -d -f <branch-name>

The above command, we can use -D instead of -f and -d

git branch -D <branch-name>
Git Delete Local Branch

Step 2: Delete Git Remote Branch

To delete the remote branch you would need to make use of the git push origin followed by -d or --delete flag and the branch name,

git push origin --delete <branch-name>


git push origin -d <branch-name>
Git Delete Remote Branch

Have Questions? Post them here!

Top Hashtags: