-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauto_commit.sh
More file actions
executable file
·35 lines (29 loc) · 836 Bytes
/
Copy pathauto_commit.sh
File metadata and controls
executable file
·35 lines (29 loc) · 836 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/bin/bash
# Default branch is 'master'. Change it to 'main' or any other default branch as needed.
BRANCH="master"
COMMIT_MESSAGE=""
# Parse command-line options
while getopts "b:" opt; do
case $opt in
b) BRANCH="$OPTARG";;
\?) echo "Invalid option -$OPTARG" >&2; exit 1;;
esac
done
# Remove the parsed options from the positional parameters
shift $((OPTIND -1))
# The first remaining argument is the commit message
COMMIT_MESSAGE=$1
# Check if a commit message was provided
if [ -z "$COMMIT_MESSAGE" ]; then
echo "Please provide a commit message."
exit 1
fi
# Perform Git operations
git add --all
if git commit -m "$COMMIT_MESSAGE"; then
git push -u origin "$BRANCH"
echo "Changes committed and pushed to branch: $BRANCH"
else
echo "An error occurred while trying to commit and push changes."
exit 1
fi