Skip to content

Instantly share code, notes, and snippets.

@davidfuhr
Last active October 28, 2019 11:08
Show Gist options
  • Save davidfuhr/9364795 to your computer and use it in GitHub Desktop.
Save davidfuhr/9364795 to your computer and use it in GitHub Desktop.
git snippets
# delete all local merged branches with no activity within the last week
for k in $(git branch --merged | sed /\*/d); do
if [ -z "$(git log -1 --since='1 week ago' -s $k)" ]; then
echo git branch -d $k
fi
done
# delete all merged remote branches with no activity within the last month
for k in $(git branch -r --merged | cut -d ' ' -f3 | sed /\*/d); do
if [ -z "$(git log -1 --since='1 month ago' -s $k)" ]; then
echo git push origin $(echo $k | sed 's/origin\//:/')
fi
done
# list all unmerged remote branches with no activity within the last month
for k in $(git branch -r --no-merged | sed /\*/d); do
if [ -z "$(git log -1 --since='1 month ago' -s $k)" ]; then
echo `git log -1 --pretty=%aN $k` $k
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment