LoginSignup
448
366

More than 5 years have passed since last update.

[git] gitconfigで会社用アカウントと個人用アカウントを楽に使い分けする

Last updated at Posted at 2019-03-26

概要

やむを得ない事情でgitアカウントが複数あり、会社用アカウントと個人用アカウントなどを分けたいケースがあると思います。
そういったときは、会社用アカウントで作業するフォルダと個人用アカウントで作業するフォルダを分け、gitconfigの includeIfこのフォルダ配下ならこのアカウントを使うよ という設定を書いてあげるとよさげです。

ベースとなるgitconfigを作り、分けたいアカウントの数だけ[user]だけ描いたgitconfigを作ってincludeIfで参照するといい感じだと思います。

ベースgitconfig

~/.gitconfig
省略

# workフォルダの時会社用gitアカウントに切り替え
[includeIf "gitdir:~/project/work/"]
  path = ~/.gitconfig-work

# otherフォルダの時は個人用アカウントを使用する
[includeIf "gitdir:~/project/other/"]
  path = ~/.gitconfig-other

会社用gitconfig

~/.gitconfig-work
[user]
  email = ***@***.co.jp
  name = ***

個人用gitconfig

~/.gitconfig-other
[user]
  email = ***@gmail.com
  name = SugarShootingStar

はるか昔に見た参考記事

git configをプロジェクトによって使い分ける - Qiita

448
366
3

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
448
366