Skip to content

Instantly share code, notes, and snippets.

@felixrabe
Last active December 20, 2015 19:29
Show Gist options
  • Save felixrabe/6184057 to your computer and use it in GitHub Desktop.
Save felixrabe/6184057 to your computer and use it in GitHub Desktop.
gitrl
#!/bin/bash
n=50 # default
if [[ $1 != "do" && $1 != "undo" ]] ; then
echo "Usage: gitrl { do [N=$n] | undo }"
exit 1
fi
n=${2:-$n}
if [[ $1 = do ]] ; then
git reflog --pretty=tformat:%h | head -n "$n" | sort | uniq | while read b ; do
echo git branch -f "reflog-$b" "$b"
git branch -f "reflog-$b" "$b"
done
elif [[ $1 = undo ]] ; then
git branch | fgrep reflog- | while read b ; do
git branch -D "$b"
done
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment