Skip to content

Instantly share code, notes, and snippets.

@pirtleshell
Created April 18, 2018 00:35
Show Gist options
  • Save pirtleshell/6fb953d096b5844b9524bba624416d92 to your computer and use it in GitHub Desktop.
Save pirtleshell/6fb953d096b5844b9524bba624416d92 to your computer and use it in GitHub Desktop.
wanna commit? bash boilerplate
# this bad boy checks for uncommitted changes, and if there are some, it
# asks you if you want to commit. if you do, it adds everything and asks
# one more time. You enter either a commit message or 'cancel'.
if [[ -z `git status --porcelain` ]]; then
echo your branch is clean, do stuff
else
echo -n you have uncommitted changes, do you want to commit?' '
read WANT_COMMIT
if [[ $WANT_COMMIT == 'y'* ]]; then
echo you want to commit
else
echo you don\'t want to commit
fi
fi
# we want to commit, let's get a commit message
# if the message is 'cancel' or empty, we don't commit.
if [[ $WANT_COMMIT == 'y'* ]]; then
git add -A
git status
echo Enter a commit message. To cancel, hit Ctrl+C or type \'cancel\':
echo -n Commit message:' '
read COMMIT_MSG
if [[ $COMMIT_MSG == 'cancel' ]]; then
echo Not committing changes.
git reset
elif [[ -n $COMMIT_MSG ]]; then
echo git -m \'$COMMIT_MSG\'
git commit -m "$COMMIT_MSG"
echo Changes have been committed
else
echo No message provided, not committing changes
git reset
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment