Skip to content

Instantly share code, notes, and snippets.

@malkam03
Last active August 9, 2023 10:16
Show Gist options
  • Save malkam03/1661edb91d984c3fd61b8601e04e12f7 to your computer and use it in GitHub Desktop.
Save malkam03/1661edb91d984c3fd61b8601e04e12f7 to your computer and use it in GitHub Desktop.
Bash script to do a git add and a git commit with message in one line and with multiple files.
#!/bin/bash
echo "Adding and commiting files"
# loop for all files until reach to a -m
while [ "$1" != "" ] && [ "$1" != "-m" ]; do
#Print the file name that is being added
echo "Adding to staging area $1"
#Adds the file
git add "$1"
#Go to the next parameter
shift
done
#if theres a -m just shift
if [ "$1" == "-m" ]
then
shift
fi
#if the last parameter is blank then return a error, else commit with the last parameter as the message
if [ "$1" == "" ]
then
echo "Error: The commit message is empty, the files where added but no commit will be performed."
else
git commit -m "$1"
fi
@Markbaro
Copy link

Markbaro commented Mar 6, 2023

so what is the exact command to run this alias

@YusufYuso
Copy link

so what is the exact command to run this alias

./git-add-commit.sh add here the files you want to add to stage and commit seperated by spaces -m "add here your commit message"

you then need to push them by doing git push -u origin main

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