Updated on: 07/20/2022
In essence, the branching model offered by Git is meant to help you avoid merging unstable code into the main codebase. Most Git workflows and Git fork strategies require developers to remove Git branches at some point in the development process; often after a branch has merged with the main branch.
Deleting Git branches is
generally considered good repository hygiene because it speeds up the performance of your repository and ensures that only the most current and necessary information is contained in your project
.
In this article, we’ll cover how to delete local branches of Git
using the GitKraken CLI and client. View your Git branches using the GitKraken GIT CLI and client Delete local branch office using the Git CLI Delete local branch using GitKraken Client Git
- Delete Local Branch FAQ
- using the CLI
- and the GitKraken client
- Git
View your Git branches
Before you can delete a local
branch
, you must obtain the exact name of the branch you want to delete.
To access a complete list of local Git branches in your project through the CLI, type git branch and press Enter. The terminal will return a list of all local branches in your Git repository.
We use GitKraken Client in
this example, but it is important to note that if you are using a terminal other than GitKraken Client, you will only be able to view the information contained in the terminal itself. With GitKraken Client,
you can combine the speed and efficiency of the CLI with the convenient images offered in a GUI. Which means you can take advantage of the built-in terminal as well as easily visualize your Git branches simply by taking a look at the incredibly powerful client confirmation graph. Level up your workflow and try GitKraken Client for free!
Learn more about how to view your
list of Git branches, including how to view your local and remote Git branches from the CLI and GitKraken Client.
Once you’ve identified the exact name of the Git branch you want to delete, you can move on to actually delete the branch.
Git Delete
local branch using the CLI
To delete a local Git branch using the terminal, run the following: git
branch
-d <branch name
>.
Note that if you are using a terminal other than the GitKraken Client, you will not have immediate visual confirmation that the Git branch has been successfully removed from your repository. Instead, you will need to run the git branch again to see the list of Git branches and make sure that the desired Git branch has been deleted.
Git Delete Local Branch Using GitKraken Client
As we have already mentioned, there are significant benefits associated with using the
GitKraken Client to visualize your repository.
If you want to delete Git a local branch using the GitKraken Client, simply right-click on a branch name in the left pane or center chart and select Delete <branch name>.
Git delete a local branch by mistake? Never fear. You can always use the Undo magic button on the top toolbar in GitKraken Client to make it look like the error never happened.
Want to make deleting local branches on Git quick and easy? Download GitKraken Client for free.
Once you are comfortable deleting local branches of Git, continue to improve your Git skills by learning how to delete a REMOTE Git branch using CLI and GitKraken Client.
Git
Delete Local Branch
FAQ Q: Why can’t I delete a local branch of Git
? A: Git does not
allow you to delete a local branch if you have the branch checked out. If you’re having trouble deleting a Git branch, be sure to check out Git a different branch than the one you want to delete.
Q: How do I delete a local branch with unmerged changes in Git?
A: To delete a local Git branch with unmerged changes, you will need to run:
git branch -D <branch name>
This tells
Git
that you are serious about removing this branch. But be careful! Using the -D flag can often make data loss very easy, so use it with caution.