⚠️

`git push`実行時に、突然エラーが出るようになった。

2023/04/29に公開約1,300字

問題

git pushを実行したらエラーが出て、git pushが出来ない。

エラー

remote: Invalid username or password.
fatal: Authentication failed for `リポジトリ名`

調査

Gitのアクセストークンの期限が切れている可能性があるので、確認します。

Expired on Thu, Apr 27 2023.
(2023年4月27日(木)に有効期限切れ。)

期限切れなので、原因が判明しました。

解決

1.先程のスクリーンショットの画面で、新しいアクセストークンを作成します。

2.現状を確認します。

git remote -v

origin https://seka-tanaka:アクセストークン@github.com/リポジトリ名.git (fetch)
origin https://seka-tanaka:アクセストークン@github.com/リポジトリ名.git (push)

3.新しいアクセストークンを設定する

git remote set-url origin https://seka-tanaka:`新しいアクセストークン`@github.com/リポジトリ名.git

4.設定確認します。

git remote -v

origin https://seka-tanaka:新しいアクセストークン@github.com/リポジトリ名.git (fetch)
origin https://seka-tanaka:新しいアクセストークン@github.com/リポジトリ名.git (push)

5.git pushする

Enumerating objects: 4, done.
Counting objects: 100% (4/4), done.
Delta compression using up to 8 threads
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 1.69 KiB | 1.69 MiB/s, done.
Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
To https://github.com/seka-tanaka/`リポジトリ名`.git
   c8b8320..72335e3  main -> main

解決!

終わりに..

このエラーが出るときは大体それが原因です。

はい、案の定アクセストークンの期限が切れていましたっと…
しかも2日前にね…久々に勉強しようとしたら出鼻をくじく原因No.1です。

これからも同じことが間違いなく起きるので、
頭に叩き込むために自分で記事を書いてみました。

Discussion

ログインするとコメントできます