Programmer
Programmer

Reputation: 8727

Delete a local development branch

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.

Upvotes: 49

Views: 61063

Answers (3)

Deeksha Sharma
Deeksha Sharma

Reputation: 3359

The branch which you are on currently cannot be deleted so create a new branch

git checkout -b new_branch

then delete the branch you want to delete

git branch -d develop

Upvotes: 0

Víctor López
Víctor López

Reputation: 817

Adding to Nandu Kalidindi's answer:

When you clone a repo, it will always have a master branch. This master branch, shouldn't be deleted. And if you want to delete it anyway, you must push another branch before, so git will recognize the new pushed branch as the new master branch.

So, in your case, if you want to delete the repo you should try a UNIX command (rm -rf).

Upvotes: 1

Nandu Kalidindi
Nandu Kalidindi

Reputation: 6280

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

Upvotes: 81

Related Questions