Open In App

How to Delete Local Branch in Git?

Last Updated : 05 May, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

Git is a widely used distributed version control and source code management system. It effectively tracks changes to source code, enabling effortless branching, merging, and versioning.

What are Local Branches?

In Git, branches are lightweight pointers to commits in the repository’s history. Each branch represents an independent line of development, allowing for parallel work on different features or fixes. Local branches are branches that exist only in your local repository and are not shared with others until you push them to a remote repository.

Steps to delete a branch

Step 1: To get all local git branches in your project via the CLI

 git branch
Screenshot_2024-04-24-12-52-30_1920x1080

git branch

Step 2: To delete a branch locally type

git branch -d <branch name>

Sometimes git refuse to delete local branches when it contains commits that haven’t been merged into any other local branches or pushed to a remote repository. Hence, for forcefully delete a branch type

git branch -D <branch name>
Screenshot_2024-04-24-13-00-01_1920x1080

Output

By following these steps you can easily delete local branch in git.


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads