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?

Windows PCでgit pushを行うまで

Posted at

この記事について

Windows PCから自分のGithubのレポジトリに変更を加えたく、環境を整備していました。途中でつまづきポイントがあったので、備忘録がてら整理しようと思います。

環境

OS: Windows 11

Windowsにgitを導入する。

Windowsにgitが入っていない人は下記のページを参考にして導入してください。
https://prog-8.com/docs/git-env-win

1. sshキーの生成

まずはsshキーを生成します。

shell
$ ssh-keygen -t ed25519 -C "your e-mail address"

Overwriteするかどうか聞かれます。yにしないと進めないので一旦yにしました。将来何かトラブルが起きるかもしれませんがそれはそのときで。

shell
 Generating public/private ed25519 key pair.
 Enter file in which to save the key (C:\Users\sophytoeat/.ssh/id_ed25519):     
 C:\Users\sophytoeat/.ssh/id_ed25519 already exists.
 Overwrite (y/n)? y

パスキーの設定を聞かれます。ここで何かパスキーを入力するとgit push の度にパスキーを聞かれることになるので、セキュリティ上問題がなければパスキーを入力せずにエンターキーを押します。

shell
 Enter passphrase (empty for no passphrase):
 Enter same passphrase again:

2. 公開鍵の登録

公開鍵の表示とコピー

以下のコマンドで公開鍵が表示されるので、それを全てコピーする。

shell
$ cat C:\Users\username\.ssh\id_ed25519.pub 

3. sshキーの登録]

生成された公開鍵をクリップボードにコピー。

shell
$ pbcopy < ~/.ssh/id_ed25519.pub

Githubにコピーした公開鍵を追加する

GitHubの「Settings(設定)」から「Deploy keys」を選択(Github pageのリポジトリでは「SSH and GPG keys」ではなく「Deploy keys」になっていた)し、「Add deploy key」をクリックします。
※この時に「Allow write access」にチェックを入れるのを忘れないように

4. ssh接続をテスト

shell
$ ssh -T git@github.com 

以下が表示されると成功。

shell
 Hi sophytoeat/sophytoeat.github.io! You've successfully authenticated, but GitHub does not provide shell access.

5. git pushまで

プッシュ先のリモートリポジトリを指定。URLはGitHubの作成したリポジトリ画面を開いて、 「HTTPS/SSH」と書かれたボタンの「SSH」を押してください。 git@github.comから始まる1行をコピーして<URL> の部分にペーストしてください。

shell
$ git remote add origin <URL>

以下のコマンドを入力するとpushが出来るはずです。

shell
$ git add .
$ git commit -m "test"
$ git push

参考文献

https://prog-8.com/docs/git-env-win
https://qiita.com/suke_qiita/items/0ce8b55d0b8af4258dc6

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?