Introduction
🧑💻 New to Git or LabEx? We recommend starting with the Quick Start with Git course.
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.
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.
- Navigate to the cloned repository:
cd git-playground
- View current branches:
git branch
- Delete the
feature-1branch:
git branch -d feature-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>.