Skip to content

Instantly share code, notes, and snippets.

Last active January 14, 2022 17:24
What would you like to do?
Creates a backup of your uncommitted changes.
set -e
old_stash_count=$(git stash list | wc -l)
git stash push --keep-index --include-untracked --quiet
if test "$old_stash_count" == "$(git stash list | wc -l)"; then
echo "All changes have been committed."
exit 0
if test "$(git rev-parse 'autosave':)" == "$(git rev-parse 'stash@{0}':)"; then
echo "Tree is identical to last autosave."
git tag -f "$(date +'autosave-%Y%m-%d%H%M')" 'stash@{0}'
git branch -f 'autosave' 'stash@{0}'
echo -n "Autosaved at: "
git rev-parse --short=7 'stash@{0}'
git stash pop --quiet
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment