Skip to content

Instantly share code, notes, and snippets.

@hritik5102
Created March 29, 2021 19:26
Show Gist options
  • Save hritik5102/de6a6e9d2092310f40736e1b9e1d93b7 to your computer and use it in GitHub Desktop.
Save hritik5102/de6a6e9d2092310f40736e1b9e1d93b7 to your computer and use it in GitHub Desktop.
Automate repetitive tasks with custom Git commands
#!/bin/sh
# Run the file inside terminal
# $ bash git-automation.sh "Commit message"
echo "Git Automation Starts ....."
message=$1 # First parameter will be the commit message
currentBranch=$(git symbolic-ref --short -q HEAD) # Getting the current branch
if [ ! -z "$1" ] # checking if the commit message is present. If not then aborting.
then
git status
read -p "Do you want to push the changes ? [Y/N] : " user_var
if [[ "$user_var" == "y" || "$user_var" == "Y" || "$user_var" == "yes" ]]
then
git add .
git commit -m "$message"
git push origin $currentBranch
else
echo "Pushing changes is incomplete"
fi
else
echo "Commit message is not provided"
fi # closes the if statement
@hritik5102
Copy link
Author

@hritik5102
Copy link
Author

hritik5102 commented Mar 29, 2021

Demo

image


image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment