Open In App

How to Delete Local Branch in Git?

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

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>

Output

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

Article Tags :