Languages
[Edit]
EN

Git - delete local branch

6 points
Created by:
ParaEagle
724

In this short article we would like to show how to remove local branch in git.

Run following command:

git branch -d my_branch_name

or

git branch --delete my_branch_name

 

Example output:

john@ubuntu-pc:/home/john/Projects/shop$ git branch -d Task-43-user-login-ui
Deleted branch Task-43-user-login-ui (was 3968585).

Notes:

  • do not forget to checkout to other branch from my_branch_name before delete operation - below example shows how to do it,
  • go to this article to know how to remove remote branch.

Removing with force example

The branch must be fully merged in its upstream branch, or in HEAD if no upstream was set with --track or --set-upstream-to.

Alternatively we can run delete with force, parameter -D

# -D - Shortcut for --delete --force.
git branch -D my_branch_name

Removing active branch example

This section shows how to remove branch that we are currently using.

Run:

git checkout master
git branch -d my_branch_name

Example output:

john@ubuntu-pc:/home/john/Projects/shop$ git branch -d Task-43-user-login-ui
error: Cannot delete branch 'Task-43-user-login-ui' checked out at '/home/john/Projects/shop'

john@ubuntu-pc:/home/john/Projects/shop$ git checkout master
Switched to branch 'master'
Your branch is up to date with 'origin/master'.

john@ubuntu-pc:/home/john/Projects/shop$ git branch -d Task-43-user-login-ui
Deleted branch Task-43-user-login-ui (was 3968585).

john@ubuntu-pc:/home/john/Projects/shop$ 

 

Alternative titles

  1. Git - remove local branch
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

Git

Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join