0

I delete the local and remote branch like this:

git branch -D logout
git push origin :logout

but when I do:

git-get-branches

this is alias that I have in .zshrc:

alias git-get-branches='git fetch; git branch -r | grep -v '\''\->'\'' | while read remote; do git branch --track "${remote#origin/}" "$remote"; done'

I still get:

Branch 'logout' set up to track remote branch 'logout' from 'origin'.

Why does the logout branch always reappear even though I delete it on my computer and on remote origin?

Vladimir Despotovic
  • 3,200
  • 2
  • 30
  • 58
  • Any chance you aren't pruning remote branches in your repo, and also deleting the remote branches from outside of your local repo? (You could try deleting the remote branch from the command line in your local repo and see if it then stays gone.) – TTT Nov 02 '21 at 20:09
  • As explained, I am already deleting the remote branch from terminal using the command git push origin :logout – Vladimir Despotovic Nov 02 '21 at 20:10
  • Oh right- somehow I missed that in the first line. ;) – TTT Nov 02 '21 at 20:11
  • The question is about deleting the remote branch. – Vladimir Despotovic Nov 02 '21 at 20:11
  • Forget the alias for now; what does `git branch -a` show immediately after you run `git push origin :logout`, then after you run `git fetch`? – chepner Nov 02 '21 at 20:14
  • doing git remote prune origin solved my problem. Whoever posts that as answer will get the answer selected as correct. I would do it myself, but I would need two days of waiting. – Vladimir Despotovic Nov 02 '21 at 20:17
  • What version of Git are you using? I actually cannot replicate my answer. If I delete the remote branch from the command line, it also automatically prunes my copy of it. (Which is why I worded my first comment the way I did.) – TTT Nov 02 '21 at 21:05

1 Answers1

1

The problem is that you're deleting the local branch, and also the remote branch on the server, but you aren't deleting your local copy of the remote branch (which is referenced by origin/logout).

You can (and usually should) remove your local copy or branches that no longer exist on the remote by pruning them.

You can also use a config to always prune when you fetch:

git config --global fetch.prune true

TTT
  • 22,611
  • 8
  • 63
  • 69