Skip to content

Instantly share code, notes, and snippets.

@cheshirecode
Last active May 24, 2022 11:44
Show Gist options
  • Save cheshirecode/0193f00d795cc52efca2c977e88324aa to your computer and use it in GitHub Desktop.
Save cheshirecode/0193f00d795cc52efca2c977e88324aa to your computer and use it in GitHub Desktop.
git helper scripts
#!/usr/bin/env sh
# get dangling commits
git fsck --no-reflog \
| awk '/dangling commit/ {print $3}' \
| xargs -L 1 git --no-pager show -s --format="%ci %H" \
| sort
# https://coderwall.com/p/euwpig/a-better-git-log
# commits by author
git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' \
--abbrev-commit \
--author="$1" \
--no-merges
# clean up old branches
for branch in `(git branch -r --merged | grep -v -e master -e whatever-names-to-leave-out; git branch -r --no-merged | grep -v -e master -e HEAD )`; do
if [ -z "$(git log -1 --since='July 08, 2017' -s $branch)" ]; then
branch_name_with_no_origin=$(echo $branch | sed -e "s/origin\///");
echo deleting branch: $branch_name_with_no_origin;
git push origin --delete $branch_name_with_no_origin;
fi;
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment