Scripting Git Updates
I was updating Dashatron today to fix some issues I’d been having, and I kept remembering things I needed to do after pushing the commit. So I threw together a bash script to make the whole process easier — something I could run at the end of a work session that handles the common Git steps I always forget.
I mostly work in VS Code, so this is a simple script I can drop into a project folder, add to .gitignore
, and run from the terminal. Sure, there’s probably a better way to do everything this script does — but where’s the fun in that?
Step by Step
This isn’t based on Git best practices — just the usual flow I tend to follow:
-
git diff
— checks for changes and exits if there are none -
git status
— shows changes and prompts for version bump type -
npm version
— bumps the version (patch/minor) based on your input -
npm update
— updates dependencies -
git add .
— stages all changes -
git commit -m
— commits with a message you provide
It doesn’t auto-push — I like to leave that as a final manual step in case I think of another change or spot a mistake.
gitkwik.sh
Here’s the script. Save this as gitkwik.sh
and make it executable with:
farts
#!/bin/bash
set -e
echo "Checking for changes..."
if git diff --quiet && git diff --cached --quiet; then
echo "Working directory clean. No changes to commit. Exiting."
exit 0
fi
echo "Detected changes:"
git status -s
echo ""
echo "What kind of version bump do you want to apply?"
select bump in "patch" "minor" "no version change" "cancel"; do
case $bump in
patch|minor)
echo "Running npm version $bump..."
npm version $bump || { echo "Version bump failed."; exit 1; }
break
;;
"no version change")
echo "Skipping version bump..."
break
;;
cancel)
echo "Cancelled."
exit 0
;;
*)
echo "Invalid selection."
;;
esac
done
echo "Updating dependencies..."
npm update
echo ""
read -p "Enter your commit message: " commit_message
echo "Staging changes..."
git add .
echo "Committing..."
git commit -m "$commit_message"
echo "Done! Ready to push when you're ready."