How to Delete a Branch Locally and Remotely: Step-by-Step Guide

Need to clean up old branches in your Git repository?

Whether you’ve finished working on a feature or just want to tidy up, deleting branches locally and remotely is something every developer should know.

This guide will walk you through deleting branches step by step—both locally and remotely—so your workspace stays organized.

How to Delete a Branch Locally and Remotely

Steps to follow:

1. To see list of local branches, run command 'git branch'.

2. Select the branch you want to delete and run the command 'git branch -D branch_name' to force delete it.

3. After deleting the branch locally, remove it remotely with 'git push origin --delete branch_name'.

4. To verify branch deletion, run:

For local branches: 'git branch'

For remote branches: 'git branch -r'

That’s it!

This is how you delete a branch locally and remotely.

Conclusion

Keeping your repository clean means less clutter, making it easier for everyone on your team to stay focused.

Now, go ahead and keep your Git workspace as streamlined as your code!

Still have questions?

Send an email to archana@leadwalnut.com, OR

Book a FREE consultation with an expert developer here.