0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

SourceTreeでGitHub複数アカウントをリポジトリごとに使い分ける方法

0
Posted at

SourceTreeでGitHub複数アカウントを使い分けるためのGit設定3つ

SourceTreeで複数のGitHubアカウントを使っていると、以下のような問題が起こることがある。

  • どの名前でコミットされるのか分からない
  • 別アカウントのメールアドレスでコミットしてしまう
  • PushのたびにOAuth認証を求められる

今回は、リポジトリごとに以下の3つを設定する。

git config user.name "your-name"
git config user.email "your-email@example.com"
git config credential.useHttpPath true

user.name

git config user.name "your-name"

コミットに記録される作者名を設定する。

--globalを付けなければ、現在のリポジトリだけに適用される。

確認する場合は以下である。

git config user.name

user.email

git config user.email "your-email@example.com"

コミットに記録されるメールアドレスを設定する。

GitHub上で正しいアカウントにコミットを紐づけたい場合は、そのGitHubアカウントに登録しているメールアドレス、またはGitHubのnoreplyメールアドレスを設定する。

確認する場合は以下である。

git config user.email

credential.useHttpPath true

git config credential.useHttpPath true

HTTPS認証情報をgithub.com単位ではなく、リポジトリのパスまで含めて扱うようにする設定である。

複数のGitHubアカウントを使っている場合、この設定によってリポジトリごとに認証情報を分けやすくなる。

自分の環境では、この設定を入れる前はPushのたびにOAuthログインを求められていたが、

git config credential.useHttpPath true

を設定したところ、毎回ログインする必要がなくなった。

確認する場合は以下である。

git config credential.useHttpPath

以下が返れば設定済みである。

true

まとめ

複数GitHubアカウントをSourceTreeで使う場合、各リポジトリで以下を設定しておくと分かりやすい。

git config user.name "your-name"
git config user.email "your-email@example.com"
git config credential.useHttpPath true

それぞれの役割は以下の通りである。

設定 役割
user.name コミット作者名を設定する
user.email コミット作者のメールアドレスを設定する
credential.useHttpPath true リポジトリごとにHTTPS認証情報を分ける

特に重要なのは、コミットに記録されるユーザー情報と、Push時の認証アカウントは別物であるという点である。

user.nameuser.emailはコミット情報を決める設定であり、credential.useHttpPathはHTTPS認証の使い分けに関係する設定である。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?