How to push local files to git with a single line code

Have you ever typed git asd . instead of git add . ? Ever forgotten to write the -m part in git commit -m "my message" ? Been tired of writing down the same three lines over and over ? As a daily basis dev, we generally hate repetitive tasks and GUI solutions : this is why I created a simple bash script to wrap it all together through a single line code.

Table of contents

Context

I have precisely 2 constraints in my context :

  1. Add all changed files from my local machine to my remote default branch.
  2. Add an optional message to my commit, and if it’s empty, there is a default message.

The solution

In a bash file push at the root directory, add the following script.

echo
echo adding files...
echo
git add .
echo
echo commiting files...
echo
git commit -m "\"${1:-commit with default msg}\""
echo
echo pushing files...
echo
git push
echo
echo done !

Results

And now we are from this :

git add .
git commit -m "this is a commit message"
git push

to this :

bash push "this is a commit message"

Simple and efficient !