Fully synchronize remote branches
The feature request
There are many branches on desktop, but some branches only exist locally after my merged pr, but remote no longer exist. I want to synchronize the local branch number with the remote branch number. Otherwise, although the number of my prs increases, my local branches will increase, and it will become more and more difficult to find.
Proposed solution
I think we can add a button to perform this operation. Of course, this will be destructive to local git information, so you can add a dialog pop-up window to warn and confirm the operation twice.
Additional context
It seems that this operation is only performed on a certain branch, which I think is cumbersome.
https://github.com/desktop/desktop/pull/11923
Hi @RSS1102, thanks for reaching out. Github Desktop automatically removes local branches that no longer exist on the remote. We do so very carefully though in order to not delete branches that may still be of use.
The logic is fairly well explained in https://github.com/desktop/desktop/blob/ac3cfab2762f0b94c6f5184c5dc3dcb8e6eb13b7/app/src/lib/stores/helpers/branch-pruner.ts#L130-L249
In short, we attempt to prune branches that meet all the following criteria
- Has been merged into the default branch (typically
git branch --merged main) - Hasn't been checked out locally in the last 2 weeks
- Are tracking a remote branch that no longer exists (i.e. the PR has been merged and the branch on the remote deleted)
- Isn't named such that it's likely to be a default branch (i.e. main, trunk, develop, etc etc).
Can you see anything in the above that would explain why your branches aren't deleted?
You can open a log file from GitHub Desktop and search for "[BranchPruner]" to get more information about this process. To access the log files go to the file menu in GitHub Desktop and select Help > Show Logs in Finder (macOS) or Explorer (Windows).
Github Desktop automatically removes local branches that no longer exist on the remote. We do so very carefully though in order to not delete branches that may still be of use.
As I said, whether to add a button to allow users to choose to force sync all branches own or fork. Let users take their own risks to confirm.
about
- Has been merged into the default branch (typically git branch --merged main)
- Hasn't been checked out locally in the last 2 weeks
- Are tracking a remote branch that no longer exists (i.e. the PR has been merged and the branch on the remote deleted)
- sn't named such that it's likely to be a default branch (i.e. main, trunk, develop, etc etc).
"Are tracking a remote branch that no longer exists (i.e. the PR has been merged and the branch on the remote deleted)" Seems to have something to do with this. Some of my prs have been merged onto remote branches that were forked. But I deleted the fork branch on github manually.
2024-10-16T01:25:13.083Z - info: [ui] [AppStore] loading 35 repositories from store
2024-10-16T01:25:13.083Z - info: [ui] [AppStore] found account: RSS1102 (阿菜 Cai)
2024-10-16T01:25:13.101Z - info: [ui] [BranchPruner] Last prune took place yesterday - skipping
2024-10-16T01:25:13.439Z - info: [ui] launching: 3.4.6 (Windows 10.0.22621)
2024-10-16T01:25:13.442Z - info: [ui] execPath: 'C:\Users\v_sshuairen\AppData\Local\GitHubDesktop\app-3.4.6\GitHubDesktop.exe'
2024-10-16T01:25:13.813Z - info: [ui] Subscribed 'RSS1102' to Alive channel
2024-10-16T01:25:17.272Z - info: [ui] [BranchPruner] Last prune took place 23 hours ago - skipping
2024-10-16T01:30:42.767Z - info: [ui] Executing fetch: git fetch --progress --prune --recurse-submodules=on-demand origin (took 1.079s)
2024-10-16T02:03:11.788Z - info: [ui] Executing fetch: git fetch --progress --prune --recurse-submodules=on-demand origin (took 1.153s)
2024-10-16T02:16:02.916Z - info: [ui] credential-helper: found GitHub credential for https://github.com/ in store
2024-10-16T02:16:04.105Z - info: [ui] Executing push: git push origin main:main --progress (took 2.049s)
2024-10-16T02:16:06.300Z - warn: [ui] fetchRepository: 'RSS1102/dynamic-collapse' returned a 404
2024-10-16T06:50:32.215Z - info: [main] Received possible protocol arguments: 3
2024-10-16T06:50:32.227Z - info: [main] Processing protocol url
2024-10-16T06:50:32.227Z - info: [main] Using toast activator CLSID {27D44D0C-A542-5B90-BCDB-AC3126048BA2}
2024-10-16T06:50:32.922Z - info: [ui] [AppStore] loading 35 repositories from store
2024-10-16T06:50:32.922Z - info: [ui] [AppStore] found account: RSS1102 (阿菜 Cai)
2024-10-16T06:50:33.454Z - info: [ui] launching: 3.4.6 (Windows 10.0.22621)
@RSS1102 I'm going to reference this in https://github.com/desktop/desktop/issues/13310 where we are tracking the option to prune branches. Thanks for the feedback.