-
-
Save stack/486408 to your computer and use it in GitHub Desktop.
#!/bin/bash | |
case "$1" in | |
'place1') | |
git config --global user.name "Your Name" | |
git config --global user.email foo@bar.com | |
;; | |
*) | |
git config --global user.name "Your Other Name" | |
git config --global user.email bar@baz.com | |
;; | |
esac | |
git config --global user.name | |
git config --global user.email |
//git_switcher.js
const { promisify } = require('util');
const exec = promisify(require('child_process').exec)
const getGitUser = async function switchGitUser() {
// Exec output contains both stderr and stdout outputs
let nameOutput = await exec('git config --global user.name')
let emailOutput = await exec('git config --global user.email')
nameOutput= nameOutput.stdout.trim(),
emailOutput= emailOutput.stdout.trim()
if(nameOutput==='username1'){
await exec('git config --global user.name "username1"')
await exec('git config --global user.email email_add_1')
}else{
await exec('git config --global user.name "username2"')
await exec('git config --global user.email email_add_2')
}
nameOutput = await exec('git config --global user.name')
emailOutput = await exec('git config --global user.email')
nameOutput= nameOutput.stdout.trim(),
emailOutput= emailOutput.stdout.trim()
console.log(nameOutput,emailOutput)
}
switchGitUser()
See http://www.shortround.net/2010/07/22/git-switch/