Created
September 15, 2021 18:15
-
-
Save katesclau/0e748700521ad6e8e606c5c0e1dd4a49 to your computer and use it in GitHub Desktop.
Push script to add, commit and push in a single action
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash | |
## Ref: https://www.redhat.com/sysadmin/arguments-options-bash-scripts | |
############################################################ | |
# Help # | |
############################################################ | |
Help() | |
{ | |
# Display Help | |
echo "Script to push local changes to ." | |
echo | |
echo "Syntax: push [-a|h] -m 'commit-message'" | |
echo "options:" | |
echo "a Add all." | |
echo "m Commit with Message." | |
echo "h Print this help." | |
echo | |
} | |
############################################################ | |
############################################################ | |
# Main program # | |
############################################################ | |
############################################################ | |
message="pushing changes..." | |
############################################################ | |
# Process the input options . # | |
############################################################ | |
# Get the options | |
while getopts ":amh" option; do | |
case $option in | |
h) # display Help | |
Help | |
exit;; | |
a) # display Help | |
git add . | |
m) # display Help | |
message=$OPTARG;; | |
\?) #Invalid option | |
echo "Error: Invalid option" | |
exit;; | |
esac | |
done | |
git commit -m "$message" && git push |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment