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?

【備忘録】Gitで毎回認証を求められる事案を回避する

Posted at

ときおり、意図せぬヒューマンエラーによって設定がおかしくなり、Gitのpushやpullに対して毎回認証を求められる…という事象が発生します。

初学者に対してレクチャーをするときは特に発生します。
長年、いまひとつクリティカルな答えへ辿り着けずにいたのですが、設定を弄る中で「これだ!」となったので、

URL … https://hogehoge.com/username/myrepo.git
ユーザ名 … username
メールアドレス … username@fugafuga.com
パーソナルアクセストークン … accesstoken

として、GitBash上で表題の事案を回避していきましょう。
※筆者はWinユーザーです。


# Git init済みのローカルリポジトリ
$ cd ~/myrepo

# もしもgit config設定済みだったらスキップしてどうぞ
# --local, --globalはお任せします
$ git config --global user.name username
$ git config --global user.email username@fugafuga.com

# 認証求められちゃう人はこの時点で求められる
# git credential managerが表示されて、ユーザ名とパスワードの入力を求められちゃう(もしくはアクセストークンのみ)
$ git pull

# これが特効薬(リポジトリ毎に設定すること)
$ git remote set-url origin https://username:accesstoken@hogehoge.com/username/myrepo.git

# 認証求められなくなれば成功
$ git pull

おそらくGitHub,BitBucket,GitLab全部に共通して使える設定。今後も検証していくけどようやくスッキリしました。

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