The most frustrating thing with Git is that I keep making commits to repositories with the wrong name and email. All the time! To solve this, I have this entry in my global Git config:

user.name=Vaidas Pilkauskas
user.email=(none)

This simply says that I need my name to stay the same across all repositories, but I want my email to vary according to the organization. To solve this, I’ve written a small script.

#!/bin/bash

ORIGIN=$(git config --get remote.origin.url)

if [[ $ORIGIN == *"wix"* ]]
then
  echo "Setting user info to Wix for the project"
  git config user.email [email protected]
else
  echo "Setting user info to personal for the project"
  git config user.email [email protected]
fi  

This script tries to detect the organization of the repo I work on (I am employed by Wix.com) and picks the email accordingly. After I freshly clone a repository, the first commit fails if I haven’t run this script.