Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I remove a branch in GitBash?

Hemang Joshi@SOLO MINGW64 ~ (add-hemang-joshi)

Hii, I am new to GitHub and I want to know that what is this, and why it is showing every time and how can I remove it? (add-hemang-joshi) is in green colour in GitBash. See the image as well.

I tried using:

git branch -D add-hemang-joshi

but didn't work and showed an error viz.

error: Cannot delete branch 'add-hemang-joshi' checked out at 'C:/Users/7386-856
15SG 2913642'

My gitBash looks like this

like image 898
Hemang Joshi Avatar asked Jul 05 '26 11:07

Hemang Joshi


1 Answers

You couldn't delete the branch you are on currently. So checkout to the other branch and then delete the required branch.

git checkout master 

The above command switches to the master branch.

git branch -d add-hemang-joshi

The above command would delete the add-hemang-joshi branch.

Adding to the above

The -d option will delete the branch only if it has already been pushed and merged with the remote branch. The -D is to force delete a branch even if it hasn't been pushed or merged yet.

like image 62
Krithick S Avatar answered Jul 08 '26 14:07

Krithick S



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!