5

I'm trying to delete a branch on git both locally and remotely. And I think I've been successful. Thing is it still shows up remotely when I do a 'git branch -a'

I did this to delete it locally:

git branch -d branchToDelete

and this to delete it remotely:

git push origin --delete branchToDelete

I think I deleted it successfully on both ends.

If I do git pull branchToDelete

I get the following fatal: 'branchToDelete' does not appear to be a git repository fatal: Could not read from remote repository.

Which I thought means it no longer exists remotely?

But if I do

git branch -a

Then it still shows up in the list

remotes/origin/branchToDelete

So why does it keep showing up if it's deleted both locally and remotely?

And yes, the branch is/was named the same both locally and remotely.

Thanks much

Tim
  • 443
  • 2
  • 5
  • 13
  • You could try doing a `git fetch` just in case it might be necessary to sync up your tracking branches with the remote after doing the remote deletion. – Tim Biegeleisen Nov 09 '21 at 04:19
  • It should be ok how you do it. What version of git are you using? – kapsiR Nov 09 '21 at 07:23
  • Was recently discussed: https://stackoverflow.com/q/69816331/7976758 Found in https://stackoverflow.com/search?tab=newest&q=%5bgit%5d%20deleted%20branch – phd Nov 09 '21 at 10:55

1 Answers1

7

You need to do a git fetch -p to prune (remove) local tracking branches of remote branches that have been deleted.

Chris Dodd
  • 119,907
  • 13
  • 134
  • 226
  • 1
    When using `git push` with `--delete` this shouldn't be necessary – kapsiR Nov 09 '21 at 07:22
  • 3
    @kapsiR: yes, but only for the one repository from which you (*you*, not someone else) ran `git push --delete`: probably in this case someone else did the delete, or Tim (OP) did it from another repository, etc. – torek Nov 09 '21 at 08:13