What is the git branch -d command in Git?

Git is one of the most renowned version control systems with several features that make it unique and different from other version control systems. One such feature is the way Git manages branches.

A branch is an independent repository that exists separately from the main line of development. The developers write new code in a branch, so the main line of development does not get disturbed. When the new addition to the code is to be finalized, the branch is merged into the main branch.

In Git, the git branch command is used to manipulate branches of a project. We can perform operations like creation, deletion, renaming, etc., by using different options with it.

The -d option

We use different options with the git branch command to perform different operations. One of these options is the -d option.

The -d option is used to delete a git branch from the local machine. Note that -d is a safe option; this means that a branch will not be deleted if its changes have not been merged into the main branch.

Note that we can use the ‘-d’ option to force delete a branch without merging its changes into the main branch.

Syntax

The following snippet of code shows the correct syntax of using the git branch command with the -d option:

git branch -d branch_name

In the above snippet of code, branch_name will be replaced by the name of the branch that is to be deleted.

After the branch is deleted from the local machine, it might still exist on the remote repository. To delete the branch from the remote machine, we execute the following command:

git push origin --delete branch_name

In the above snippet of code, branch_name will be replaced by the name of the branch that has been deleted.

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved