git – set your commit email address in folders

git – set your commit email address in folders

You can use git config user.email to set a different email address from global one for each folder. Here’s a bash snippet.

#!/bin/bash

# Define the root directory containing all your folders
ROOT_DIR="/path/to/your/directories"
# Define the email you want to set for each Git repository
GIT_EMAIL="your-email@example.com"

# Loop through each folder in the root directory
for dir in "$ROOT_DIR"/*; do
  if [ -d "$dir" ]; then
    cd "$dir"
    
    # Check if the folder is a Git repository
    if [ -d ".git" ]; then
      echo "Setting git user.email for $dir"
      git config user.email "$GIT_EMAIL"
    else
      echo "$dir is not a Git repository"
    fi

    # Return to the root directory
    cd "$ROOT_DIR"
  fi
done

16. Sep 2024