How can I refresh already deleted Git remote branches?
Answered
I know I have to use VCS->Git->Fetch to refresh remote inventories, but that does not delete from the list branches that I have already deleted in Github. How can I do that? I think "Fetch" should do it, to be honest.
Please sign in to leave a comment.
Hello Borja
IDE runs command “fetch <name> --progress --prune”. The command deletes stale references associated with <name>, but in your case, it doesn’t work as expected.
IDE completely relies on information provided by Git’s output in the console.
When you run “Fetch”
Could you please run “git branch -r” from the terminal and share a screenshot of output so we could see how it works without IDE’s interaction?
Best Regards
Ruslan Kuleshov
JetBrains Support
Hello Borja
Thank you for the screenshot.
Yes, please run “git fetch --prune -v” and see the results.
Best Regards
Ruslan Kuleshov
JetBrains Support
Hello Borja
Thank you for contacting JetBrains support.
Could you please also clarify whether a branch is not deleted from the list of "Remote branches" once fetch is performed?
Or perhaps you would like a branch to be deleted locally as well if it doesn't exist in a remote repository?
Looking forward to your reply.
Best regards
Ruslan Kuleshov
JetBrains Support
Hello Ruslan,
I have a remote server in Bitbucket. The list of remote branches right now (after deleting old ones) is:
As you can see, there are only 12 branches there. Nevertheless, the list of remote branches in IntelliJ has the old ones:
Performing a VCS->Git->Fetch I can see new remote branches appear, but the old ones that are now deleted are not being deleted in the IDE. Is it clearer now?
Regards,
Borja
Hello Ruslan,
It gives the list that appears in the IDE:
If I press return it gives two more lines (just in case you are missing them)
Should I run any "fetch" command from te Terminal to test?
Hello Ruslan,
They are there:
According to: https://community.atlassian.com/t5/Git-questions/remote-branches-are-not-removed-from-the-list-after-being/qaq-p/423090 the local branches are not removed automatically. I could delete them manually, but it it will be perfect if Intellij could do it for me.
Hello Borja
Judging by the git fetch output, the branches you see as remote are not deleted on the server. So git fetch does not remove the references despite the --prune flag.
You can check what branches are actually on the server using git ls-remote.
If for some reason Bitbucket UI shows a different list of branches than git ls-remote, please contact the Bitbucket team.
The discussion you linked mentions local branches (those the are listed as local in git branch output) tracking remote, which are indeed not removed by fetch. Here is the request to add such a feature to the IDE https://youtrack.jetbrains.com/issue/IDEA-154892
However in your case, these are not local branches, but references to the remote branches in the local repository. They should be removed by the fetch with the --prune flag - see origin/JTPPM-4176 in the output - but only if the branch is not present on the remote anymore.
Best Regards
Ruslan Kuleshov
JetBrains Support
Thanks a lot for your time on this. I feel embarrassed, but after your last comment everything is now clear. If you look at my first snapshot from Bitbucket it was only showing the active branches. Some developers have been merging branches without deleting them (which could have sense in some case, but not here) and that is the reason I am seeing them in Intellij. I will clear them up.
Borja
For anyone arriving here from a search on how to get the IDE list to refresh, who wants to get their local branches pruned but the above referenced issue isn't added yet, you can add
to an executable shell script if you're on *nix or MacOS. If you want a one liner it's
And if you're on Windows, eh, I'm feeling lazy and don't want to boot to Windows instead of Elementary OS on my personal computer during work hours. I might try to figure it out some other time.
Also note that if you click the widget in the status bar it still might not update; you may have to go to the Git->Branches... menu option before it will refresh (at least that was my experience in PyCharm).