how to automate the “commit-and-push” process? (git)

You can very easily automate this using Bash scripting.

git add .

echo 'Enter the commit message:'
read commitMessage

git commit -m "$commitMessage"

echo 'Enter the name of the branch:'
read branch

git push origin $branch

read

store the above code as a .sh file(say gitpush.sh)

And since you have to make this sh file an executable you need to run the following command in the terminal once:

chmod +x gitpush.sh

And now run this .sh file.

Each time you run it, It will ask you for the commit message and the name of the branch. In case the branch does not exist or the push destination is not defined then git will generate an error. TO read this error, I have added the last read statement. If there are no errors, then git generates the pushed successfully type-of message.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)