In some cases, it might be useful to have a one-liner in order to delete local unused branches.įor those who are curious, here is how you can delete unused local branches in one single line. Now that your local branches are cleaned-up, let’s see how you can delete the remote tracking branches from your Git repository. If you are sure you want to delete it, run 'git branch -D branch'. $ git branch -d Įrror: The branch 'branch' is not fully merged. If there are any differences between the branches, you will have to use the “ -D” option to delete the branch locally. To see differences between your local branch and your remote-tracking branch, execute the “git diff” command.
$ git branch -D Īs you probably already know it, you have a local branch but you also have a remote-tracking which is a branch set to represent the state of your remote branch (also called the upstream branch).Īs a consequence, if you perform a commit on your local branch without pushing it to the remote branch, your remote-tracking branch will be behind your local branch, thus unmerged. In this case, the “-D” option stands for “ –delete -force” and it is used when your local branches are not merged yet with your remote tracking branches. The other way of cleaning up local branches on Git is to use the “git branch” command with the “-D” option. If your branch is named “feature” for example, to clean up this branch, you would run $ git branch -d releaseĭeleted branch feature (was bd6903f). The “-d” option stands for “ –delete” and it can be used whenever the branch you want to clean up is completely merged with your upstream branch. The easiest way to delete local Git branches is to use the “git branch” command with the “-d” option. Now that you have the local branches already merged with master, you will need to delete them. If you omit to provide the commit hash, the command will imply that you are referring to HEAD (also known as the last commit of your current branch). To check merged branches, use the “git branch” command with the “–merged” option. In this case, we are going to imply that you want to delete local branches merged with master.
First of all, you want to check which branches have already been merged with your current branch.