Search code examples
gitgithubgit-branchgit-bashgit-commit

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


Solution

  • We can't delete a branch sitting on that branch. So, you need to checkout to another branch then delete the branch.

    $ git checkout master
    

    If master branch does not exist in your local then create and checkout to a new branch (e.g. add-hemang-joshi_2):

    $ git checkout -b add-hemang-joshi_2
    

    Delete the branch add-hemang-joshi:

    $ git branch -D add-hemang-joshi  # delete the branch
    
    $ git branch                      # check if the branch is deleted