first commit
This commit is contained in:
72
Linux/Development/PUSH-TO-DEVELOPMENT.sh
Normal file
72
Linux/Development/PUSH-TO-DEVELOPMENT.sh
Normal file
@@ -0,0 +1,72 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Exit immediately if a command exits with a non-zero status.
|
||||
set -e
|
||||
|
||||
# Function to display a message in red color
|
||||
error() {
|
||||
echo -e "\e[31m$1\e[0m"
|
||||
}
|
||||
|
||||
# Function to display a message in green color
|
||||
success() {
|
||||
echo -e "\e[32m$1\e[0m"
|
||||
}
|
||||
|
||||
# Ensure we're inside a Git repository
|
||||
if ! git rev-parse --git-dir > /dev/null 2>&1; then
|
||||
error "Error: This directory is not a Git repository."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Get the current branch name
|
||||
CURRENT_BRANCH=$(git symbolic-ref --short HEAD)
|
||||
|
||||
# Check if the current branch is 'development'
|
||||
if [ "$CURRENT_BRANCH" != "development" ]; then
|
||||
error "Error: You are not on the 'development' branch."
|
||||
echo "Please switch to the 'development' branch and run this script again."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Prompt for a commit message
|
||||
echo "Enter your commit message:"
|
||||
read -r COMMIT_MESSAGE
|
||||
|
||||
# Check if the commit message is empty
|
||||
if [ -z "$COMMIT_MESSAGE" ]; then
|
||||
error "Error: Commit message cannot be empty."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Add all changes
|
||||
git add .
|
||||
|
||||
# Show the changes to be committed
|
||||
echo "The following changes will be committed:"
|
||||
git status --short
|
||||
|
||||
# Prompt for confirmation to commit
|
||||
echo "Do you want to proceed with the commit and push to 'development' branch? (yes/no)"
|
||||
read -r CONFIRMATION
|
||||
|
||||
if [ "$CONFIRMATION" != "yes" ]; then
|
||||
error "Aborting commit and push to 'development' branch."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Commit the changes with the provided message
|
||||
git commit -m "$COMMIT_MESSAGE"
|
||||
|
||||
# Show the last commit
|
||||
echo "Last commit on 'development' branch:"
|
||||
git --no-pager log -1 --pretty=format:"%h - %s (%an, %ar)"
|
||||
echo
|
||||
|
||||
# Pull the latest changes from the remote 'development' branch
|
||||
git pull origin development --rebase
|
||||
|
||||
# Push the 'development' branch to the remote repository
|
||||
git push origin development
|
||||
|
||||
success "Successfully pushed changes to 'development' branch."
|
||||
Reference in New Issue
Block a user