0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ローカルでGitHubアカウントを使い分けようとしたら少し失敗した

Last updated at Posted at 2017-11-13

普段GitHubを仕事以外で使ってこなかったので、ローカルのgitのユーザ情報は会社で使用しているアカウントを登録しています。

最近ようやく個人でもGitHubを使い始めたのですが、ローカルのgitのユーザ情報の切り替えに苦戦したのでメモしておきます。

新規GitHubアカウントを取得

会社用のアカウントをそのまま使うのに抵抗があったので個人のアカウントを取得しました。

テストとして個人のGithub Pagesを作成しようとリモートリポジトリも作りました。

ローカルでリモートリポジトリをclone

作成したリモートリポジトリをcloneして作業開始です。

simple is bestなhtmlを作成し、addしてcommitします。

GitHubを使ってないだけでgitは使ってきたのでなんら脅威はありません。

リモートリポジトリにpush

問題発生しました。

ERROR: Permission to <個人アカウント>/<個人アカウント>.github.io.git denied to <会社用アカウント>.
fatal: Could not read from remote repository.

なんと会社のアカウントでpushしようとしているではありませんか!

※良い子はpushの前にgit logで確認しましょう

原因1

git config user.nameとgit config user.emailを確認したら会社のアカウントになっていました。(変えてなかった)

早急に設定を個人用アカウントに変えました。
git commit --amend --author "xxxxx "でコミットした情報も書き換えたので一安心です。

原因2

そういえばssh keyの設定を全くしていなかったので原因1を修正したのと同タイミングでssh keyの設定も行いました。
~/.ssh/configに以下の内容を追加しました。

Host github-xxxx
    HostName github.com
    IdentityFile ~/.ssh/<秘密鍵のファイル名>
    User git

ここまでもしても会社用アカウントでpushしようとします。

原因3

原因2でsshの設定をしましたが、その設定内容に不足があるようです。

こちらのページを参考に、IdentitiesOnly yesの項目を付け足したらpushできました。

git cloneした時に会社のアカウント情報になっていたので、それが使われていたみたいですね。

確認

ユーザのGithub Pagesはhttps://<アカウント>.github.ioで確認できます。

無事表示されることを確認できました。

まだまだ駆け出しのGitHubユーザですが、使いこなせる日が来るのでしょうか?

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?