0
1

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 push で詰まった問題と対処法

Posted at

はじめに

プロジェクトをcreateして、GitHubのリポジトリと連携しpushするまでのフローで、pushでエラーが出たので、備忘録として残しておきます。
同じ問題に遭遇した人がいたら、ぜひ参考にしてください。

Repository not found. エラー

原因

  • Private リポジトリに git push する際、HTTPS 認証が必要なため、認証エラーが発生

解決策

  1. Personal Access token を作成、
  2. 作成したtokenを使用し認証を行いpushを行う

Personal Access Token の作成方法

  1. GitHub にログイン
  2. 右上のアイコンから Settings に移動
  3. 左サイドバーの Developer settings をクリック
  4. 左メニューの Personal access tokens → Tokens (classic) を選択
  5. Generate new token (classic) をクリック

【以下の項目を設定】

  • Note: Git Push Token(トークンの用途をメモ)
  • Expiration: 90 days 以上(推奨)
  • Scopes(権限): repo(リポジトリへのアクセスを許可)
  • Generate token をクリック
  • 表示されたトークンをコピー!(再表示できないので必ずメモする)

作成したtokenを使用し認証を行いpushを行う

$ git remote -v
$ git remote set-url origin https://<USERNAME>:<TOKEN>@github.com/<REPONAME>.git
$ git push -u origin main

上記を実行することで、git pushが成功します。

まとめ

ステップ やること
1. Repository not found. エラーの原因を確認 Private リポジトリで HTTPS 認証が必要
2. Personal Access Token を作成 repo 権限をつけた Personal Access token を生成
3. git remote set-url で Token を設定 git remote set-url origin https://<USERNAME>:<TOKEN>@github.com/...
4. git push -u origin main を実行 トークンを使った HTTPS 認証で push
0
1
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
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?