Last active
October 31, 2017 08:35
-
-
Save ufuk/6fda2b5c6c3b43c0f2d7b56aba686b59 to your computer and use it in GitHub Desktop.
Lists git branches ordered by last change time to find out which ones are stale branches.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# DESCRIPTION | |
# ----------- | |
# | |
# Produces CSV output like this: | |
# | |
# LAST CHANGE TIME, TIME ELAPSED, AUTHOR, BRANCH | |
# 2017-01-16 14:56:26 +0000, 3 months ago, [email protected], origin/bug-fix-1 | |
# 2017-01-23 18:27:53 +0300, 2 months ago, [email protected], origin/new-feature-1 | |
# 2017-01-31 19:25:59 +0300, 2 months ago, [email protected], origin/new-feature-1 | |
# 2017-02-06 19:26:20 +0300, 4 weeks ago, [email protected], origin/new-feature-1 | |
# 2017-02-20 19:51:03 +0300, 2 weeks ago, [email protected], origin/bug-fix-2 | |
# 2017-03-03 10:53:57 +0300, 5 days ago, [email protected], origin/master | |
# ... | |
# | |
# You can grep "months ago" including lines. (or whatever you wish) | |
# Then replace using this regex ".+origin/" with "git push origin --delete ". | |
# Finally you will have a command list that deletes stale branches. | |
# | |
# For example, in a git repository's root run this command: | |
# | |
# bash ../find-out-stale-branches.sh | grep "months ago" | perl -pe "s/.*origin\//git push origin --delete /" | |
# | |
# Then it'll produce something like this: | |
# | |
# git push origin --delete bug-fix-1 | |
# git push origin --delete new-feature-1 | |
# git push origin --delete ... | |
# Print header | |
echo | |
echo "LAST CHANGE TIME, TIME ELAPSED, AUTHOR, BRANCH"; | |
# Prepare report | |
for branch in `git branch -r | grep -v HEAD`; do | |
echo -e `git show --format="%ci,%cr,%ae" $branch | head -n 1`,$branch; | |
done | sort | sed 's/,/, /g' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment