Skip to content

Instantly share code, notes, and snippets.

@changa
Last active August 29, 2015 14:01
Show Gist options
  • Save changa/6f9e3dd8c36b89f4b0d6 to your computer and use it in GitHub Desktop.
Save changa/6f9e3dd8c36b89f4b0d6 to your computer and use it in GitHub Desktop.
Git-wip : git stash straight to a dedicated branch
#!/bin/sh
# vim: set ft=sh :
if [ $# -ne 1 ]; then
echo "List of WIP branches:"
git branch|grep -e '^wip_'
else
if [ -z "$(git ls-files)" ]; then
echo "No files to stash in the staging area" >&2
exit 1
fi
new_branch_name="wip_${1}"
git stash --quiet && \
git checkout --quiet -b $new_branch_name && \
git stash pop --quiet && \
git commit --quiet -am "WIP" && \
git checkout --quiet -
echo "Stored files in ${new_branch_name} branch"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment