EN
Git - delete local branch
6 points
In this short article we would like to show how to remove local branch in git.
Run following command:
xxxxxxxxxx
1
git branch -d my_branch_name
or
xxxxxxxxxx
1
git branch --delete my_branch_name
Example output:
xxxxxxxxxx
1
john@ubuntu-pc:/home/john/Projects/shop$ git branch -d Task-43-user-login-ui
2
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.
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
xxxxxxxxxx
1
# -D - Shortcut for --delete --force.
2
git branch -D my_branch_name
This section shows how to remove branch that we are currently using.
Run:
xxxxxxxxxx
1
git checkout master
2
git branch -d my_branch_name
Example output:
xxxxxxxxxx
1
john@ubuntu-pc:/home/john/Projects/shop$ git branch -d Task-43-user-login-ui
2
error: Cannot delete branch 'Task-43-user-login-ui' checked out at '/home/john/Projects/shop'
3
4
john@ubuntu-pc:/home/john/Projects/shop$ git checkout master
5
Switched to branch 'master'
6
Your branch is up to date with 'origin/master'.
7
8
john@ubuntu-pc:/home/john/Projects/shop$ git branch -d Task-43-user-login-ui
9
Deleted branch Task-43-user-login-ui (was 3968585).
10
11
john@ubuntu-pc:/home/john/Projects/shop$