Home > Mobile >  Git branch always magically appears even though I delete it
Git branch always magically appears even though I delete it

Time:11-03

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?

CodePudding user response:

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

  • Related