Delete a local development branch

Programmer picture Programmer · Nov 10, 2017 · Viewed 51.8k times · Source

I have recently cloned a repo of our development code branch in my system:

git clone https://gitserver.com/product

After the clone was successful I get the below status on query:

$ git branch
* develop

I realized that now this branch needs to be deleted, hence:

$ git checkout develop
Already on 'develop'
Your branch is up-to-date with 'origin/develop'.

$ git branch -d develop
error: Cannot delete branch 'develop' checked out at 'C:/work/test'

I am not sure whether we should try a GIT command or Unix command 'rm -rf' to delete a local develop branch repository? Lastly why no one can delete 'develop' branch.

Answer

Nandu Kalidindi picture Nandu Kalidindi · Nov 10, 2017

You cannot delete the branch you are currently on.

Try creating a new branch

git checkout -b new-branch

Then delete the develop branch

git branch -d develop