Automating the Git Add, Commit and Push Process

Automating the Git Add, Commit and Push Process

·

1 min read

To automate the git add, git commit, and git push commands, you can write a simple script in any language like Bash.

Let us create a simple bash script that automate this 3 processes of add, commit and push, instead of typing them out everytime we want to push changes in our current directory.

#!/bin/bash

echo "Enter commit message;"

read message

git add .

git commit -m '$message'

git push

Save this code in a file with the .sh extension, for example (push.sh)

To use make use of the push.sh file, you have to give it executable permission with the chmod command:

// give the file executable command
chmod 700 push.sh
// anytime you want to use the git add, commit and push to push changes in 
// your current working directory, just run/execute your push.sh

./push.sh

After running “./push.sh”, the command line will prompt you for commit message, input your commit message and hit enter, so anytime you need to git add, commit,push just run your ‘push.sh’ script.

The script will automatically add all changes, commit them with a default message, and push them to the remote repository.

If you need to push to a different branch or repository, you will need to modify the script accordingly.

That's it!