#!/bin/bash
branch=$(git branch --format='%(refname)')
ahead=$(git for-each-ref --format="%(upstream:track,nobracket)" "$branch" | awk '/ahead/{print$2}')
commits=($(git log --no-show-signature --pretty=format:%H | head -n $ahead | tac))
n=0
printf "%s\n" "${commits[@]}" |
while read c
do
((++n))
git show --no-show-signature --patch-with-stat $c > $n-$c.patch
done