- It retrieves the name of the default branch from the remote repository using the
git ls-remote
command. - It checks out the
default
branch locally. - It lists all local branches using the
git for-each-ref
command. - For each local branch, it finds the merge base between the default branch and the current branch using the
git merge-base
command. - It creates a temporary commit tree for the current branch using the
git commit-tree
command. - It checks if the temporary commit is a descendant of the default branch using the
git cherry
command. - If the temporary commit is not a descendant (i.e., the branch has been merged into the default branch), it prints a message indicating that the branch can be deleted.
Essentially it fakes a squash merge for each branch and then checks of the default branch is a decendent from this.
It will also print the branches that were merged in the "normal" way, i.e. git merge
.