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,

Command:
git branch --delete <branch-name>

You can also make use of the shorthand version -d

Example:
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.

Example:
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,

Command:
git push origin --delete <branch-name>

or,

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 is a seasoned developer with over 10 years of experience in web and app development, and a deep knowledge of operating systems. Author of insightful How-To articles for Code2care.

Follow him on: X

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