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?

7
  • 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.) Commented Nov 2, 2021 at 20:09
  • As explained, I am already deleting the remote branch from terminal using the command git push origin :logout Commented Nov 2, 2021 at 20:10
  • Oh right- somehow I missed that in the first line. ;) Commented Nov 2, 2021 at 20:11
  • The question is about deleting the remote branch. Commented Nov 2, 2021 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? Commented Nov 2, 2021 at 20:14

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.