Date

元々、zshrcに以下の様なコマンドを作っていた。

function github_current_user() {
  local user_name=`git config user.name`
  echo "\ue709:${user_name}"
}

function gitmain() {
    git config --global user.name "main_github_username"
    git config --global user.email "main_github_email"
    source ~/.zshrc
}

function gitsub() {
    git config --global user.name "sub_github_username"
    git config --global user.email "sub_github_email"
    source ~/.zshrc
}

ターミナル上でgitmainコマンドを実行すると、main_githubのアカウントを使用し、
gitsubコマンドを実行するとsub_githubのアカウントを使用する様にしていた。

これはこれで便利だったが、
コマンドを実行しない限り、githubアカウントの切り替えが発生しない。
そのため、sub_githubアカウントでcommitすべきリポジトリでmain_githubアカウントでcommitしてしまう。
という事故が発生した。


そこで、.gitconfig

[includeIf "gitdir:~/PROJECTS/hogehoge/"]
    path = ~/.gitconfig_sub

と追加し、.gitconfig_sub

[user]
    name = sub_github_username
    email = sub_github_email

とした。
これにより、~/PROJECTS/hogehoge/配下では、自動的にsub_githubアカウントを使用する様になった。

これで、Githubアカウントを間違えるという事故が無くなるはず。