Skip to content

Instantly share code, notes, and snippets.

@tcarreira
Created March 10, 2021 13:16
Show Gist options
  • Save tcarreira/40065310d08a7a30df8e4cdd77139eb4 to your computer and use it in GitHub Desktop.
Save tcarreira/40065310d08a7a30df8e4cdd77139eb4 to your computer and use it in GitHub Desktop.
Config git USER+EMAIL for every repository inside a directory
#!/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