LoginSignup
0
2

githubアカウントを仕事用・プライベート用で簡単に切り替える方法

Last updated at Posted at 2023-05-27

概要

備忘録としてgithubアカウントを仕事用・プライベート用で分けるにはどうすれば良いかという記事を
書きます。

環境

  • M2 macbook Air(Ventura 13.2.1)

修正する場所

.zshrcを開く。
開いた後に下記を追加する。
追加した後は.zshrcを閉じる。またターミナルも再起動する。

function gitMain() {
  git config --global user.name "<仕事用のgitのアカウント名>"
  git config --global user.email "<仕事用のメールアドレス>"
  git config --list
}

function gitSub() {
  git config --global user.name "<プライベート用のgitのアカウント名>"
  git config --global user.email "<プライベート用のメールアドレス>"
  git config --list
}

それぞれ関数を設定した後にターミナルでそれぞれのコマンドを叩くと、切り替えることができる。

  • gitMain
  • gitSub

補足(.zshrcが無い場合)

.zshrcの場所はホームディレクトリを参照する。
もし.zshrcが無い場合はホームディレクトリで以下コマンドを叩き、作成する。

touch ~/.zshrc

Finderを開いた後、メニューバーの「ホーム」をクリック。
「command + shift + .」 で作成されたかどうかを確認する。

0
2
0

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
0
2