Kev Quirk

A Script to Automate Git Add, Commit & Push

19 Feb 2023

I wanted a way to automate the git add, commit & push commands. Here's how I did it...

Since learning how to use Git, it has become an integral part of my workflow for things like publishing to this site, and updating my various projects, like Simple.css and That Watch Bloke. However, pushing changes to a Git repository can get tedious, as it involves 3 commands. Every. Single. Time:

git add *
git commit -m "Your commit message..."
git push

I use VSCodium to write code, which integrates with Git, making things easier. But I still wanted a way to automate the process of committing to my Git repositories without having to enter those 3 commands, over and over again.

Plus, if I'm writing a post (like this very one), I'm not in VSCodium. I'm typing the post in Typora; so being able to flip to the command line and enter a single command, would be great.

BASH script

Since I use an M1 Macbook Air, which is basically Unix under the hood, I can use good old BASH to do this. So I used the following script (thanks to StackOverflow):

read -p "Commit message: " desc
git add . && \
git commit -m "$desc" && \
git push

I then added the following line to my .zshrc file so I can call this script with a single command:

alias push=~/path/to/

If running the script fails with permission issues, run chmod +x to give the script execution rights.

So now, whenever I'm in a Git repo within my command line, all I need to do is type the command push. My script will then be called, it will ask for a commit message, then push to the repo. All automatically.

Perfect. 👌

← The one before
Micro.Blog Is Still Confusing

Up next →
My Static Site Workflow

Reply to this post

If you have thoughts on anything I've covered in this post, please use the button below to send me an email so we can have a good old chat about it.

Reply by email

Enjoyed this post?

I put a lot of work into maintaining this site and I really enjoy interacting with my readers.

My fuel of choice is coffee, so if you did enjoy this post, or found it in any way useful, I'd appreciate more fuel to keep me going. ❤️

Buy me a coffee