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

Facing issues? Have Questions? Post them here! I am happy to answer!

Author Info:

Rakesh (He/Him) has over 14+ years of experience in Web and Application development. He is the author of insightful How-To articles for Code2care.

Follow him on: X

You can also reach out to him via e-mail:

Copyright © Code2care 2024 | Privacy Policy | About Us | Contact Us | Sitemap