LoginSignup
103
105

More than 5 years have passed since last update.

githubのリポジトリにアクセスするとパスワードを求められる時の対処

Last updated at Posted at 2014-02-05

~/.netrcにIDとパスワード書けばいいよ!と言う人もいるけど平文でパスワード書くなんて恐ろしい真似はしたくないよね。

まず、なぜパスワードを求められるかと言うと、http(s)でcloneしたからと思われる。新しいリポジトリを作った時、例としてhttpsでcloneするコマンドが出てくるのでついやっちゃってるケースがありそう。

リモートのURLを確認・変更

リポジトリのディレクトリに入って

git config remote.origin.url

https://github.com/[ユーザID]/[リポジトリ] になってたら次のコマンドで変更。

git remote set-url origin git@github.com:[ユーザID]/[リポジトリ].git

公開鍵が登録されていればこれで次からパスワードは求められない。
されてなかったらAccount SettingsのSSH Keysで登録する。
登録方法はぐぐれば出てくるので各自どうぞ。

追記

コメントで情報をいただきました。

global設定に以下を追加しておくと、httpsのリポジトリにpushすると自動的にssh経由(git@github.com)に置き換えてくれる。

git config --global "url.git@github.com:.pushinsteadof" "https://github.com/"

なお、remote.origin.urlはそのままなので、pullはhttps経由になるはず。

103
105
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
103
105