git-up / GitUp

The Git interface you've been missing all your life has finally arrived.
http://gitup.co
GNU General Public License v3.0
11.43k stars 1.23k forks source link

Prune local branches for which no remote branch exists anymore #967

Open richardtop opened 5 months ago

richardtop commented 5 months ago

In a common workflow with the remote repository (GitHub/BitBucket/GitLab) the user usually merges the PR via a web interface which also often leads to a deletion of the branch.

After some time (e.g. a week), the local repository accumulates a lot of branches that don't have a corresponding remote branch.

I suggest a feature similar to "Refresh all branches" that instead of just refreshing the branches will delete all local branches that do not have a corresponding remote (because it has been deleted).

Would be great if this could also check if the branch has been merged and then prune just the merged branches to be on the safe side.

Current workaround:

breathe commented 1 month ago

Agree this would be a nice feature! I use this shell script to accomplish this -- deletes all local branches which have been merged into a branch with the name main

#!/bin/bash
git checkout main  && git pull && git branch --merged | egrep -v '(^\*|main)' | xargs -n 1 git branch -d