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のリモート接続をHTTPSからSSHに変更する手順

Posted at

1. 既存のGitリポジトリのリモートURLを確認

git remote -v

(例)HTTPS接続の場合

origin  https://github.com/ユーザー名/リポジトリ名.git (fetch)
origin  https://github.com/ユーザー名/リポジトリ名.git (push)

2. SSH鍵の生成(まだ作成していない場合)

ssh-keygen -t ed25519 -C "メールアドレス"

• ファイル名はデフォルトのまま(~/.ssh/id_ed25519)
• パスフレーズは任意(空でもOK)

生成後、公開鍵を確認

cat ~/.ssh/id_ed25519.pub

3. GitHubに公開鍵を登録

• GitHubのSSHキー設定ページにアクセス
• 「New SSH key」ボタンを押す
• タイトル(任意)を入力し、id_ed25519.pub の内容をペースト
• 「Add SSH key」をクリックして登録完了

4. SSH接続確認

ssh -T git@github.com

成功すると以下のようなメッセージが出ます

Hi ユーザー名! You've successfully authenticated, but GitHub does not provide shell access.

5. リモートURLをSSHに変更

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

例)

git remote set-url origin git@github.com:TK-19881224/product-management-app.git

変更後、再度確認

git remote -v

6. 変更したSSH接続でpushする

git push -u origin main

正常にpushできれば完了です。

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