問題
ひとつの PC で「私用」「仕事用」の git アカウント情報を切り替えたい
解決
Bash の関数を定義する
関数の定義
git config
する関数を定義する
function switch_git_config {
name="$1"
email="$2"
gpg_pub_sign="$3"
git config --global --unset-all user.name
git config --global --unset-all user.email
git config --global --unset-all user.signingkey
git config --global user.name "$name"
git config --global user.email "$email"
git config --global user.signingkey "$gpg_pub_sign"
echo "Configuration has changed:"
echo "git config user.name: $(git config user.name)"
echo "git config user.email: $(git config user.email)"
echo "git config user.signingkey: $(git config user.signingkey)"
}
関数を利用する関数の定義
先ほど定義した関数をすぐ利用できるよう、別の関数を定義する
function git_a {
switch_git_config "my_name_A" "my_name_A@example.com" "SIGN_A"
}
function git_b {
switch_git_config "my_name_B" "my_name_B@example.com" "SIGN_B"
}
「私用」「仕事用」の切り替えがすぐできるようになった