Delete a Branch

GitGitBeginner
Practice Now

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

Introduction

In Git, branches are used to develop features or isolate changes for a specific purpose. Once the changes are merged into the main branch, the branch has served its purpose and can be deleted. Deleting a branch in Git is a straightforward process.


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL git(("`Git`")) -.-> git/BranchManagementGroup(["`Branch Management`"]) git/BranchManagementGroup -.-> git/branch("`Handle Branches`") subgraph Lab Skills git/branch -.-> lab-12720{{"`Delete a Branch`"}} end

Delete a Branch

You have created a local branch in your Git repository, and you no longer need it. You want to delete the branch to keep your repository clean and organized.

  1. Navigate to the cloned repository:
cd git-playground
  1. View current branches:
git branch
  1. Delete the feature-1 branch:
git branch -d feature-1
  1. Verify that the branch has been deleted:
git branch

This is the result of running the git branch command:

* master

Summary

Deleting a branch in Git is a simple process that can help keep your repository organized. Use the git branch -d <branch> command to delete the specified local <branch>.

Other Git Tutorials you may like