55 lines
1.2 KiB
Bash
55 lines
1.2 KiB
Bash
#!/bin/bash
|
|
|
|
# Script to automate git add, commit and push
|
|
# Usage: ./push.sh "your commit message"
|
|
|
|
# Check if a commit message has been provided
|
|
if [ $# -eq 0 ]; then
|
|
echo "Error: Please provide a commit message."
|
|
echo "Usage: ./push.sh \"your commit message\""
|
|
exit 1
|
|
fi
|
|
|
|
# Get the commit message from arguments
|
|
COMMIT_MESSAGE="$1"
|
|
|
|
echo "Executing git commands..."
|
|
echo "----------------------------------------"
|
|
|
|
# git add .
|
|
echo "1. Adding all files (git add .)"
|
|
git add .
|
|
|
|
# Check if git add succeeded
|
|
if [ $? -eq 0 ]; then
|
|
echo "✓ git add . - Success"
|
|
else
|
|
echo "✗ git add . - Failed"
|
|
exit 1
|
|
fi
|
|
|
|
# git commit
|
|
echo "2. Committing with message: \"$COMMIT_MESSAGE\""
|
|
git commit -m "$COMMIT_MESSAGE"
|
|
|
|
# Check if git commit succeeded
|
|
if [ $? -eq 0 ]; then
|
|
echo "✓ git commit - Success"
|
|
else
|
|
echo "✗ git commit - Failed"
|
|
exit 1
|
|
fi
|
|
|
|
# git push
|
|
echo "3. Pushing to remote repository"
|
|
git push
|
|
|
|
# Check if git push succeeded
|
|
if [ $? -eq 0 ]; then
|
|
echo "✓ git push - Success"
|
|
echo "----------------------------------------"
|
|
echo "All git operations completed successfully!"
|
|
else
|
|
echo "✗ git push - Failed"
|
|
exit 1
|
|
fi |