2

I tried to follow instruction in this thread and apparently my local branch was deleted.

To make sure, I tried to switch to the deleted branch and expected to get error saying that the local branch no longer exists or something similar. However, I switched the the supposedly deleted branch without any issues:

PS C:\Users\node> git branch -D MKTINT-45693
Deleted branch MKTINT-45693 (was c405ae9a99).
PS C:\Users\node> git checkout MKTINT-45693
Updating files: 100% (668/668), done.
Switched to a new branch 'MKTINT-45693'
Branch 'MKTINT-45693' set up to track remote branch 'MKTINT-45693' from 'origin'.

Furthermore, the branch MKTINT-45693 is still visible in my Jira project (as a hyperlink to BitBucket repo) - I expected that after the deletion of a local branch it will also be removed from Jira project as well.

How to permanently delete local branch then?

The reason I want to delete it is that I made some changes on a file and committed to production branch but later on I had to make additional changes to the same file and re-commit. But when I try to recommit I get error saying that "branch MKTINT-45693 already exists. Please delete the local branch..". So I'm trying to delete it.

Community
  • 1
  • 1
kamokoba
  • 497
  • 9
  • 17

2 Answers2

1

Git allows you to create a local branch mapped to an upstream branch as long as one exists upstream.

Since you only deleted the local branch, but origin still has a copy of it, git allows you to quickly check out the upstream branch as a new local branch.

Deleting it locally does not delete it remotely.

If you wanted to completely get rid of the branch you have to delete it locally as well as delete it on your remote.

To do that, in addition to that git branch -D command you can use git push origin -d MKTINT-45693 to delete it on the remote.

So in order to completely delete the branch:

git branch -D MKTINT-45693
git push origin -d MKTINT-45693

Also be aware that if any other developer on the team still has the branch as a local branch in their clone, they might push it back to the upstream. There is little you can do to prevent this other than to make sure people don't push branches that they just happen to have lying around.

Lasse V. Karlsen
  • 380,855
  • 102
  • 628
  • 825
kamokoba
  • 497
  • 9
  • 17
0

The branch is still available in remote.That is why you can still checkout to that branch. Try to run the below command to delete it permanently.

git push origin :MKTINT-45693
git branch -D MKTINT-45693
Vikash
  • 46
  • 3