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.

1
9 comments

Hello Borja


IDE completely relies on information provided by Git’s output in the console.
When you run “Fetch”  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.
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

1

Hello Borja

Thank you for the screenshot.
Yes, please run “git fetch --prune -v” and see the results.


Best Regards
Ruslan Kuleshov
JetBrains Support

1

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

0

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

0

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?

 

0

Hello Ruslan,

 

They are there:

C:\Development\active-steward>git fetch --prune -v
From https://bitbucket.org/activesteward/active-steward
- [deleted] (none) -> origin/JTPPM-4176
POST git-upload-pack (gzip 1158 to 652 bytes)
remote: Counting objects: 288, done.
remote: Compressing objects: 100% (269/269), done.
Receiving objects: 89% (257/288), 60.00 KiB | 111.00 KiB/s (delta 129), reused 0 (delta 0)
Receiving objects: 100% (288/288), 118.97 KiB | 191.00 KiB/s, done.
Resolving deltas: 100% (129/129), done.
= [up to date] develop -> origin/develop
= [up to date] AST-49_develop -> origin/AST-49_develop
= [up to date] JTPPM-2867 -> origin/JTPPM-2867
= [up to date] JTPPM-2867-2 -> origin/JTPPM-2867-2
= [up to date] JTPPM-2867-3 -> origin/JTPPM-2867-3
= [up to date] JTPPM-2867-4 -> origin/JTPPM-2867-4
= [up to date] JTPPM-3496 -> origin/JTPPM-3496
= [up to date] JTPPM-3718 -> origin/JTPPM-3718
= [up to date] JTPPM-3736 -> origin/JTPPM-3736
= [up to date] JTPPM-3736-documents -> origin/JTPPM-3736-documents
= [up to date] JTPPM-3736-merge -> origin/JTPPM-3736-merge
= [up to date] JTPPM-3736-products -> origin/JTPPM-3736-products
= [up to date] JTPPM-3745-2 -> origin/JTPPM-3745-2
= [up to date] JTPPM-3745-3 -> origin/JTPPM-3745-3
= [up to date] JTPPM-3745-4 -> origin/JTPPM-3745-4
= [up to date] JTPPM-3745-6 -> origin/JTPPM-3745-6
= [up to date] JTPPM-3747 -> origin/JTPPM-3747
e6a00a7bdd..9e88595fac JTPPM-3760 -> origin/JTPPM-3760
= [up to date] JTPPM-3816 -> origin/JTPPM-3816
= [up to date] JTPPM-3821 -> origin/JTPPM-3821
= [up to date] JTPPM-3838 -> origin/JTPPM-3838
= [up to date] JTPPM-3846 -> origin/JTPPM-3846
= [up to date] JTPPM-3856 -> origin/JTPPM-3856
= [up to date] JTPPM-3873 -> origin/JTPPM-3873
= [up to date] JTPPM-3949 -> origin/JTPPM-3949
= [up to date] JTPPM-3976-XSL-approach -> origin/JTPPM-3976-XSL-approach
= [up to date] JTPPM-3984 -> origin/JTPPM-3984
= [up to date] JTPPM-4023 -> origin/JTPPM-4023
= [up to date] JTPPM-4023-2 -> origin/JTPPM-4023-2
= [up to date] JTPPM-4026-2 -> origin/JTPPM-4026-2
= [up to date] JTPPM-4086 -> origin/JTPPM-4086
= [up to date] JTPPM-4091 -> origin/JTPPM-4091
= [up to date] JTPPM-4108 -> origin/JTPPM-4108
* [new branch] JTPPM-4178 -> origin/JTPPM-4178
* [new branch] JTPPM-4198 -> origin/JTPPM-4198
* [new branch] JTPPM-4202 -> origin/JTPPM-4202
* [new branch] JTPPM-4202.2 -> origin/JTPPM-4202.2
= [up to date] astrack -> origin/astrack
= [up to date] campaign-viewmods -> origin/campaign-viewmods
= [up to date] master -> origin/master
= [up to date] removing-tonnage-caching -> origin/removing-tonnage-caching
= [up to date] selenium -> origin/selenium
= [up to date] selenium-include -> origin/selenium-include
= [up to date] with-node -> origin/with-node
= [up to date] with-typescript -> origin/with-typescript

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.

0

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

0

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

0

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

#!/usr/bin/env bash

for branch in $(git branch -v | grep "gone" | awk '{print $1}')
do
git branch -d $branch
done

to an executable shell script if you're on *nix or MacOS. If you want a one liner it's

for branch in $(git branch -v | grep "gone" | awk '{print $1}'); do git branch -d $branch; done

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).

0

Please sign in to leave a comment.