In this example, we shall learn how to delete Git local branch. To delete a branch, it must be fully merged in its upstream branch, or in HEAD if no upstream was set.
1. A brief on Git branch
A branch represents an independent line of development. These serve as an abstraction for the edit, stage, or commit process.
git branch command lets you create, list, rename, and delete branches.
git branch is tightly integrated with the
git checkout and
git merge commands.
git branch [--color[=] | --no-color] [-r | -a] [--list] [-v [--abbrev= | --no-abbrev]] [--column[=] | --no-column] [(--merged | --no-merged | --contains) ] [--sort=] [--points-at ] […] git branch [--set-upstream | --track | --no-track] [-l] [-f]  git branch (--set-upstream-to= | -u )  git branch --unset-upstream  git branch (-m | -M)  git branch (-d | -D) [-r] … git branch --edit-description 
2. Git delete local branch in Action
To see our example in action, we shall start with creating git repository.
First we shall create a directory for master branch.
Here, we shall initialize git repository using
git init command.
Once we have initialized Git repository, we shall add some file and then add and commit using
git add and
git commit command respectively.
Now we that we have created a master branch, now we shall be creating a directory where we will create a new local branch.
In this directory, we shall clone git master branch that we just created using command
Here, let’s create a new branch ReleaseBranch using command
git branch <branch name>. Available branches can be viewed using command
Now assume that all the work with the local branch is now complete and we now want to delete the same. For this purpose, we will use command
git branch -d <branch name>.
We can also use
-D option (in Uppercase) if we want to forcefully delete the branch.
In this example, we learnt the usage of
git branch command to delete local branch.