Skip to content

Instantly share code, notes, and snippets.

@katesclau
Created September 15, 2021 18:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save katesclau/0e748700521ad6e8e606c5c0e1dd4a49 to your computer and use it in GitHub Desktop.
Save katesclau/0e748700521ad6e8e606c5c0e1dd4a49 to your computer and use it in GitHub Desktop.
Push script to add, commit and push in a single action
#! /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