Top community members
All Wiki Articles Create Wiki Article

If you think it is valuable to share IT knowledge and help others.

It is the right place for you. ❀ đŸ’»

Join our community.

Git - delete local branch

0 contributions
6 points

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).

Note: do not forget to checkout to other branch from my_branch_name - below example shows how to do it.

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$ 

 

0 contributions

Checkout latest Findings & News:

Checkout latest questions:

Checkout latest wiki articles:

Hey 👋
Would you like to know what we do?
  • Dirask is IT community, where we share coding knowledge and help each other to solve coding problems.
  • We welcome everyone,
    no matter what the experience,
    no matter how basic the question is,
    this community will help you.
Read more