Deleting local git branches with a missing remote branch

I have about 100 git repositories at $job, and of those, about 90% of them have branches that were created locally that were set as tracking branches, but never pushed to a remote. It makes looking at the output of git branch very annoying, so I wrote the script below to clean up those branches.

 
git for-each-ref --format='%(refname:short)' refs/heads/* | while read branch; do
	BRANCH_EXISTS=$( git ls-remote --heads origin $branch | wc -l );
	if [ $BRANCH_EXISTS -eq 0 ]; then
		git branch -D $branch;
	fi;
done