Delete a branch
Deleting a branch in Git is an essential practice for maintaining a streamlined and organized repository. While branches provide a convenient space for feature development, bug fixing, and experimentation, there comes a time when a branch has served its purpose and is no longer needed. By removing unnecessary branches, you can declutter your repository and ensure a clean development environment.
In this part of our tutorial, we will guide you through the process of deleting a branch in Git. You will learn how to safely remove a branch that has been merged or discard a branch that is no longer required.
We successfully merged issue1
with main
in the previous step, and now we can delete it.
To delete the branch issue1
, use the git branch -d command:
$ git branch -d issue1
Deleted branch issue1 (was b2b23c4).
Verify that issue1
has been deleted using the git branch command. Only the main branch should be listed.
$ git branch
* main