Delete Merged Branches

GitGitBeginner
Practice Now

This tutorial is from open-source community. Access the source code

Introduction

When working on a project with Git, it's common to create and merge branches. However, over time, these branches can accumulate and clutter your local repository. Deleting merged branches is a good practice to keep your repository clean and organized.


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL git(("`Git`")) -.-> git/BranchManagementGroup(["`Branch Management`"]) git/BranchManagementGroup -.-> git/merge("`Merge Histories`") subgraph Lab Skills git/merge -.-> lab-12636{{"`Delete Merged Branches`"}} end

Delete Merged Branches

Your task is to delete all local branches that have been merged into the master branch of the https://github.com/labex-labs/git-playground repository.

Tasks

  1. Change to the repository directory.
  2. List all local branches that have been merged into master.
  3. Delete all merged branches.
  4. List all branches again.

This is the final result:

* master

Summary

Deleting merged branches is a good practice to keep your local repository clean and organized. Use the git branch --merged <branch> command to list all branches merged into <branch>, and the git branch -d <branch> command to delete a branch. Remember to always be careful when deleting branches, as you may lose important work if you delete the wrong branch.

Other Git Tutorials you may like