0

To make question more specific, I'll have example.

I've cloned a project from github. Then I've made some commits and pushed it. At this moment, if I type git branch & git branch -r command, I can get list of local branches and remote branches.

git branch

enter image description here

git branch -r

enter image description here

Now, if I want to remove remote branch, git push origin search -d will help.

git push origin search -d
git branch -r

enter image description here

Great. It works well.

However, If I remove this branch through the github, the problem occurs.

Since my local does not know that remote branch is removed, it still retrieves origin/search when I type git branch -r command. So I tried to use command git push origin search -d to remove origin/search from my local. However, it threw error like below

enter image description here (Sorry for Korean, It means error: failed to push some refs to 'https://github.com/njh7799/test)

HaHa. Git cannot remove the remote branch because it does not exists!

Eventually, origin/search lives forever in my local when I type git branch -r. The question is, how can I delete it?

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
Jeong Ho Nam
  • 803
  • 12
  • 20
  • 2
    Please don't put things like "" in the title; if you accept the dupe, it will be automatically marked as "[Duplicate]" – jonrsharpe Jul 29 '20 at 07:10

1 Answers1

0

This is because "git pull" does not remove remote tracking branches for branches deleted from the remote repo.

SOLUTION: To remove remote tracking branches for deleted branches, please try the following command:

git remote prune origin

If you just want to list such stale branches (and not remove them), use this:

git remote prune origin --dry-run

Reference here: https://git-scm.com/docs/git-branch