ZSH shortcut: quickly commit using a function

I have many private git repos to manage all the configuration files, ansible playbooks, source code and other stuff you would want to version. Most of them are just for me to view and often I want to quickly ‘save’ my current process by creating a commit I can go back to.

I just recently switched to zsh after years of using bash – never had I thought that my life would change that much. So many neat little things that are really helpful and make my life easier. Themes, plugins and the oh so amazing oh-my-zsh really make it a pleasure to do stuff on the console. (I always have to bite my tongue once I SSH into a server that only has sh or bash now.

So in order to commit quicker without having to write two to three commands like add, commit & push one can create a function that does all that and takes some arguments in case you need them. During my research, as any scientist should do properly before reinventing the wheel, I found Hasan has thought of the same thing a couple years back. Here is my version of it:

gitc() {
        if [ "$1" != "" ]
        then
                git commit -a -m "$1"
        else
                git commit -a -m update # default commit message is `update`
        fi
        git push
}

Enjoy!

Published by

Kordian Bruck

I'm a TUM Computer Science Alumni. Pizza enthusiast. Passionate for SRE, beautiful Code and Club Mate. Currently working as an SRE at Google. Opinions and statements in this blog post are my own.

Leave a Reply