Created
March 10, 2021 13:16
-
-
Save tcarreira/40065310d08a7a30df8e4cdd77139eb4 to your computer and use it in GitHub Desktop.
Config git USER+EMAIL for every repository inside a directory
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
GIT_USER="${GIT_USER:-My Name}" | |
GIT_EMAIL="${GIT_EMAIL:[email protected]}" | |
INFO=${INFO:-yes} | |
DIR="${1:-.}" | |
apply_git_config() { | |
target=$1 | |
[ -d "${target}/.git" ] || return | |
( | |
[ "x$INFO" = "xyes" ] && echo "INFO: Applying git config to ${DIR}/${target}" | |
cd "${target}" || { echo "failed entering ${target}."; return; } | |
git config user.name "$GIT_USER" | |
git config user.email "$GIT_EMAIL" | |
) | |
} | |
cd "$DIR" || { echo "\"$DIR\" is not a directory (or you have no permission)" ; exit 2 ; } | |
if [ -d .git ]; then | |
apply_git_config . | |
else | |
for repo in * ; do | |
apply_git_config "$repo" | |
done | |
fi | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment