Skip to content

Instantly share code, notes, and snippets.

@pv8
Last active June 21, 2016 15:18
Show Gist options
  • Save pv8/100dc28985ee522b47df3d00eaa41d9f to your computer and use it in GitHub Desktop.
Save pv8/100dc28985ee522b47df3d00eaa41d9f to your computer and use it in GitHub Desktop.
Handy script to setup git local config for several git projects
#!/usr/bin/env bash
set -e
prompt_user() {
read -p "$1 [hit <enter> to abort]: " user_input
if [[ -z "$user_input" ]]; then
echo "Aborting git local config setup."
exit 1
fi
echo $user_input
}
CODE_DIR=$(prompt_user "Type the the root dir (full path) of your projects (Example: $HOME/workspace/)?")
GIT_USER_NAME=$(prompt_user "Type your full name")
GIT_USER_EMAIL=$(prompt_user "Type your email")
CURR_DIR=$(pwd)
cd $CODE_DIR
for entry in $(ls -lrt -d -1 $PWD/*/); do
if [[ -d $entry/.git/ ]]; then
cd $entry
echo "Setting git config for $(pwd)"
git config --local user.name "$GIT_USER_NAME"
git config --local user.email $GIT_USER_EMAIL
fi
done
cd $CURR_DIR
@pv8
Copy link
Author

pv8 commented Jun 21, 2016

To run the script:

$ bash -c "$(curl -fSL https://gist.githubusercontent.com/pv8/100dc28985ee522b47df3d00eaa41d9f/raw)"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment