How to Delete a Merged Branch: 1-Min Guide

Have you ever looked at your Git repository after a big project merge and realized there are still a ton of old branches hanging around?

It can get overwhelming, especially when you’ve already merged the changes and don’t need those branches anymore.

We’ve all been there, sifting through cluttered branches and wondering how to clean them up without accidentally deleting something important. 

In this guide, let’s walk you through how to safely delete a merged branch from both your local and remote repositories, step by step.

How to Delete a Merged Branch

Discover how to safely delete a merged branch from both your local and remote repositories in just a few simple steps.

Steps to follow:

1. Open 'Terminal' of your code editor.

2. To list all the branches, use the command 'git branch'.

3. It shows the list of all branches in your repository.

4. To delete a specific branch, use the command 'git branch -d <branch-name>'.

In our example, to delete the branch 'fix/visible-password', the command would be: 'git branch -d fix/visible-password'.

5. The branch has been successfully deleted locally.

6. To delete a branch from the remote repository, use the command 'git push origin --delete <branch-name>'.

Note: You can also use '-d' instead of '--delete'.

7. The branch has been successfully deleted from the remote repository as well.

Congratulations! 🎉

You’ve successfully learned how to delete a merged branch from both your local and remote repositories.

Conclusion

Now you know how to keep your Git repository clean by deleting merged branches.

With just a few simple commands, you can remove branches you no longer need, keeping your repo organized and easy to manage.

This helps avoid confusion when working on multiple features and makes your repo easier to navigate for everyone involved.

Staying organized will save you time and hassle later!

Still have questions?

Send an email to archana@leadwalnut.com, OR

Book a FREE consultation with an expert developer here.