Skip to content

Instantly share code, notes, and snippets.

@stack
Created July 22, 2010 18:52
Show Gist options
  • Save stack/486408 to your computer and use it in GitHub Desktop.
Save stack/486408 to your computer and use it in GitHub Desktop.
A script for switching between git profiles
#!/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
@stack
Copy link
Author

stack commented Jul 22, 2010

@MOHDaazam
Copy link

//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()

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