Last active
August 9, 2023 10:16
-
-
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.
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 | |
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
./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