#!/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 . # 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 # Prompt for confirmation to push to 'production' echo "Do you want to merge 'development' into 'production' and push to the remote repository? (yes/no)" read -r CONFIRMATION if [ "$CONFIRMATION" != "yes" ]; then error "Aborting push to 'production' branch." exit 0 fi # Fetch the latest changes from the remote repository git fetch origin # Switch to the 'production' branch git checkout production # Pull the latest changes in 'production' branch git pull origin production # Merge 'development' into 'production' git merge --no-ff development -m "Merge branch 'development' into 'production'" # Push the 'production' branch to the remote repository git push origin production # Switch back to the 'development' branch git checkout development success "Successfully pushed changes from 'development' to 'production' branch."