Kev Quirk

A Script to Automate Git Add, Commit & Push

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 by email

Want to be informed when I post new articles? Simply enter your email address below and you will get an email whenever new posts are published.

Alternatively, you can subscribe via RSS instead.

Enjoyed this post?

Why not buy me a coffee? It helps support the site and caffeinates me so I can keep producing content.

Thank you! 🙏