I need to delete old and unmaintained branches from our remote repository. I\'m trying to find a way with which to list the remote branches by their last modified date, and
Here is what I came up with after also reviewing this.
for REF in $(git for-each-ref --sort=-committerdate --format="%(objectname)" \
refs/remotes refs/heads)
do
if [ "$PREV_REF" != "$REF" ]; then
PREV_REF=$REF
git log -n1 $REF --date=short \
--pretty=format:"%C(auto)%ad %h%d %s %C(yellow)[%an]%C(reset)"
fi
done
The PREV_REF
check is to remove duplicates if more than one branch points to the same commit. (As in a local branch that exist in the remote as well.)
NOTE that per the OP request, git branch --merged
and git branch --no-merged
are useful in identifying which branches can be easily deleted.
[https://git-scm.com/docs/git-branch]