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?

More than 1 year has passed since last update.

MacBookでSSHを使用してGitHubリポジトリに接続・プッシュする完全ガイド

Posted at

GitHubへのSSH接続設定

  1. SSHキーの生成:

    • ssh-keygen -t rsa -b 4096 -C "your_email@example.com" を実行して新しいSSHキーを生成しました。既存のキーを上書きするために y を選択し、パスフレーズの入力を求められた際には空白で進めました。
  2. SSHキーのGitHubへの追加:

    • 生成した公開キーを pbcopy < ~/.ssh/id_rsa.pub でクリップボードにコピーし、GitHubのアカウント設定にある「SSH and GPG keys」セクションにペーストして追加しました。
  3. SSH接続のテスト:

    • ssh -T git@github.com を実行してSSH接続が成功していることを確認しました。

GitHubへのプッシュの試みとエラーの解決

  1. リモートリポジトリの設定:

    • git remote add origin https://github.com/ogatapro/claw_crane.git を実行しようとした際に、origin が既に存在しているというエラーに遭遇しました。
  2. リモートURLの変更:

    • git remote set-url origin https://github.com/ogatapro/claw_crane.git を実行してリモートURLを更新しました。
  3. ファイルのステージングとコミット:

    • git add . でファイルをステージングし、git commit -m "コミットメッセージ" でコミットしました。
  4. HTTPS経由でのプッシュエラー:

    • git push origin master を実行した際に、パスワード認証が削除されたことによるエラーが発生しました。
  5. パーソナルアクセストークンの生成とエラー:

    • GitHubで新しいパーソナルアクセストークンを生成しましたが、プッシュ時に認証が失敗し続けました。
  6. リモートURLをSSHに変更:

    • git remote set-url origin git@github.com:ogatapro/claw_crane.git を実行してリモートURLをSSH形式に変更しました。
  7. SSH経由での成功したプッシュ:

    • 最終的に git push origin main を実行して、変更をGitHubリポジトリにプッシュし、これが成功しました。
  8. まとめ:
    SSHキーの生成、
    GitHubへのキーの追加、
    リモートURLの変更、
    ファイルのステージングとコミット、
    およびSSH経由でのプッシュ方法

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?