Skip to content

Instantly share code, notes, and snippets.

@p32929
Last active January 4, 2026 14:30
Show Gist options
  • Select an option

  • Save p32929/d6f0c4b202b5de238645805ae27763db to your computer and use it in GitHub Desktop.

Select an option

Save p32929/d6f0c4b202b5de238645805ae27763db to your computer and use it in GitHub Desktop.
#!/bin/bash
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
echo ""
echo "=================================================="
echo " Commit to All Projects"
echo "=================================================="
echo ""
# Define project directories (add more here as needed)
# Format: "directory_name:Display Name"
PROJECTS=(
"server_nestjs:Server (NestJS)"
"client_flutter:Client App (Flutter)"
"trainer_flutter:Trainer App (Flutter)"
"thrive_shared:Shared Package"
)
# Function to print colored status
print_status() {
echo -e "${BLUE}[INFO]${NC} $1"
}
print_success() {
echo -e "${GREEN}[SUCCESS]${NC} $1"
}
print_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
print_warning() {
echo -e "${YELLOW}[WARNING]${NC} $1"
}
# Function to check if directory is a git repo
is_git_repo() {
if [ -d "$1/.git" ]; then
return 0
else
return 1
fi
}
# Function to commit changes in a project
commit_project() {
local project_dir=$1
local project_name=$2
local commit_message=$3
echo ""
echo "=================================================="
print_status "Processing: $project_name"
echo "=================================================="
cd "$project_dir" || {
print_error "Failed to enter directory: $project_dir"
return 1
}
# Check if it's a git repo
if ! is_git_repo "."; then
print_warning "$project_name is not a git repository. Skipping..."
cd - > /dev/null
return 1
fi
# Check if there are any changes
if [ -z "$(git status --porcelain)" ]; then
print_warning "No changes to commit in $project_name"
cd - > /dev/null
return 0
fi
# Show git status
print_status "Git status:"
git status --short
echo ""
print_status "Adding all files..."
git add .
if [ $? -ne 0 ]; then
print_error "Failed to add files in $project_name"
cd - > /dev/null
return 1
fi
print_status "Committing with message: \"$commit_message\""
git commit -m "$commit_message"
if [ $? -eq 0 ]; then
print_success "Successfully committed to $project_name"
else
print_error "Failed to commit to $project_name"
cd - > /dev/null
return 1
fi
cd - > /dev/null
return 0
}
# Main script
echo "This script will commit changes to all projects:"
for i in "${!PROJECTS[@]}"; do
IFS=':' read -r dir name <<< "${PROJECTS[$i]}"
echo " $((i + 1)). $name"
done
echo ""
# Ask for commit message
read -p "Enter commit message: " COMMIT_MSG
# Check if commit message is empty
if [ -z "$COMMIT_MSG" ]; then
print_error "Commit message cannot be empty!"
exit 1
fi
echo ""
print_status "Commit message: \"$COMMIT_MSG\""
echo ""
print_status "Starting commit process..."
echo ""
# Track success/failure
SUCCESS_COUNT=0
TOTAL_COUNT=0
# Loop through all projects
for project in "${PROJECTS[@]}"; do
IFS=':' read -r dir name <<< "$project"
if [ -d "$dir" ]; then
TOTAL_COUNT=$((TOTAL_COUNT + 1))
commit_project "$dir" "$name" "$COMMIT_MSG"
if [ $? -eq 0 ]; then
SUCCESS_COUNT=$((SUCCESS_COUNT + 1))
fi
else
print_warning "Directory not found: $dir"
fi
done
# Summary
echo ""
echo "=================================================="
echo " Summary"
echo "=================================================="
print_success "Successfully committed: $SUCCESS_COUNT out of $TOTAL_COUNT projects"
echo ""
echo ""
echo "=================================================="
print_success "Done!"
echo "=================================================="
echo ""
#!/bin/bash
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
echo -e "${BLUE}========================================${NC}"
echo -e "${BLUE} Pushing All Projects${NC}"
echo -e "${BLUE}========================================${NC}"
echo ""
# Array of project directories
PROJECTS=(
"server_nestjs"
"client_flutter"
"trainer_flutter"
"thrive_shared"
)
# Function to push a project
push_project() {
local project=$1
echo -e "${BLUE}πŸ“¦ Processing: ${project}${NC}"
if [ ! -d "$project" ]; then
echo -e "${RED} ❌ Directory not found${NC}"
echo ""
return 1
fi
cd "$project" || return 1
# Check if it's a git repository
if [ ! -d ".git" ]; then
echo -e "${RED} ❌ Not a git repository${NC}"
cd ..
echo ""
return 1
fi
# Check if remote exists
if ! git remote get-url origin &> /dev/null; then
echo -e "${YELLOW} ⚠️ No remote configured - skipping${NC}"
cd ..
echo ""
return 0
fi
# Get current branch
BRANCH=$(git branch --show-current)
# Push
echo -e "${GREEN} πŸš€ Pushing to origin/${BRANCH}...${NC}"
git push origin "$BRANCH"
if [ $? -eq 0 ]; then
echo -e "${GREEN} βœ… Pushed successfully${NC}"
else
echo -e "${RED} ❌ Push failed${NC}"
fi
cd ..
echo ""
}
# Process each project
for project in "${PROJECTS[@]}"; do
push_project "$project"
done
echo -e "${BLUE}========================================${NC}"
echo -e "${GREEN}✨ All projects processed!${NC}"
echo -e "${BLUE}========================================${NC}"
echo ""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment