Skip to content

Instantly share code, notes, and snippets.

@MorrisJobke
Last active January 24, 2018 12:47
Show Gist options
  • Save MorrisJobke/e42359494ddd633cb18e9a844b67b4c8 to your computer and use it in GitHub Desktop.
Save MorrisJobke/e42359494ddd633cb18e9a844b67b4c8 to your computer and use it in GitHub Desktop.
Deletes all branches in a git repo of which the last commit is not authored by Morris
<?php
$branchesOutput = shell_exec('git branch | egrep -v "^\\*"');
$branches = explode("\n", $branchesOutput);
foreach ($branches as $branch) {
$branch = trim($branch);
if ($branch === '') {
continue;
}
$output = shell_exec("git show $branch | head -n 2 | grep 'Author:' | grep -v Morris -q && git branch -D $branch");
if (!empty($output)) {
echo $output;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment