Skip to content

Instantly share code, notes, and snippets.

@manhdaovan
Created March 22, 2018 02:09
Show Gist options
  • Select an option

  • Save manhdaovan/3c13c80b06de7bc16ab4ed8bbf482d65 to your computer and use it in GitHub Desktop.

Select an option

Save manhdaovan/3c13c80b06de7bc16ab4ed8bbf482d65 to your computer and use it in GitHub Desktop.
Bash: Delete local branch before time
# Usage: delete_local_branch number_of_weeks_ago
# Eg: delete_local_branch 4
function delete_local_branch() {
for k in $(git branch | sed /\*/d); do
if [ -n "$(git log -1 --before='$1 week ago' -s $k)" -a "$k" != "develop" -a "$k" != "master" -a "$k" != "staging" ]; then
echo "Delete $k"
git branch -D $k
fi
done
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment