Skip to content

Instantly share code, notes, and snippets.

@jlogsdon
Last active August 29, 2015 14:27
Show Gist options
  • Save jlogsdon/910b3434708562758f61 to your computer and use it in GitHub Desktop.
Save jlogsdon/910b3434708562758f61 to your computer and use it in GitHub Desktop.

Usage:

$ merged-branches.sh > DELETE-ME # Get all merged branches on the origin remote and put them into the DELETE-ME file
$ branch-owners.sh < DELETE-ME | sort > BRANCH-OWNERS # Map all the branches we just grabbed to the most recent author
$ delete-branches.sh < DELETE-ME # Actually delete all of the branches from origin
$ stale-branches.sh # Logs stale branches (those older than 6 months) to STALE and the rest to FRESH
#!/bin/bash
main() {
local deployment_email='eng-group-ops+deployboard@tapjoy.com'
while read BRANCH
do
local owner=$(git log --no-merges --format=tformat:%ae origin/${BRANCH} | grep -v ${deployment_email} | head -n 1)
echo "${owner} ${BRANCH}"
done
}
main $@
#!/bin/bash
main() {
echo "Failed to delete:" > FAILED-TO-DELETE
while read branch
do
local result
echo "DELETING ${branch}..."
result=$(git push origin --delete ${branch} 2>&1)
if [ $? -eq 0 ]; then
echo " Delete success"
else
echo " Delete failed"
echo "Branch: ${branch}" >> FAILED-TO-DELETE
echo -e "${result}\n" >> FAILED-TO-DELETE
fi
done
}
main $@
#!/bin/bash
set -e
main() {
usage() { echo "Usage: merged-branches" 1>&2; }
git branch $args --merged |
grep origin |
grep -v '>' |
grep -v develop |
grep -v master |
xargs -L1 |
cut -d"/" -f2- |
sort
}
main $@
#!/usr/bin/env bash
function main() {
local cutoff=$(date -d '-6 months' +'%s')
local branches=$(git branch --remote |
grep origin |
grep -v develop |
grep -v master |
xargs -L1 |
cut -d"/" -f2- |
sort)
[ -f STALE ] && rm STALE
[ -f FRESH ] && rm FRESH
for branch in $branches; do
echo "Checking ${branch}"
local timestamp=$(git log origin/${branch} --pretty=tformat:%at | head -n1)
local datetime=$(date -d@${timestamp} +'%Y-%m-%d %H:%M:%S')
if [ $cutoff -gt $timestamp ]; then
echo -e "${datetime}\t${branch}" >> STALE
else
echo -e "${datetime}\t${branch}" >> FRESH
fi
done
}
main $@
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment