I have following global git configs:
git config commit.gpgsign # true for work, false for personal
git config user.name # different for work(global) and personal
git config user.email # different for work(global) and personal
Assuming the default(global) git config is my work related configs, which I dont want to use for personal git repos
So I can switch to personal every time I work on a personal project. To change all the 3 with predetermined values, use following shell script.
#!/bin/bash
echo "Settings before update:"
git config user.name
git config user.email
git config commit.gpgsign
git config user.name "<your-personal-name>"
git config user.email "<your-personal-email>"
git config commit.gpgsign false
echo
echo "Settings updated to personal"
Create the .sh file say gitpersonal.sh
and place in a location from where it can be run anywhere (see how to run a .sh file from anywhere in gitbash and powershell)
Update: Improved script based on above. Added color. Added pause.
#!/bin/bash
# Personal Info
PERSONAL_EMAIL="anant.code@gmail.com"
PERSONAL_USER="Anant"
# Colors
RED='\033[0;31m'
LIGHTGREEN='\033[1;32m'
NC='\033[0m' # No Color
echo "in pwd:"
pwd
echo "Settings before update:"
printf "${RED}git config user.name${NC}\n"
git config user.name
printf "${RED}git config user.email${NC}\n"
git config user.email
printf "${RED}git config commit.gpgsign${NC}\n"
git config commit.gpgsign
git config user.name $PERSONAL_USER
git config user.email $PERSONAL_EMAIL
git config commit.gpgsign false
echo
echo "Settings updated to personal!"
echo "New Settings:"
printf "${LIGHTGREEN}git config user.name${NC}\n"
git config user.name
printf "${LIGHTGREEN}git config user.email${NC}\n"
git config user.email
printf "${LIGHTGREEN}git config commit.gpgsign${NC}\n"
git config commit.gpgsign
echo "press any key to close..."
read -n 1 -s