githubでcloneして編集してcommitしてpushするまでの流れのメモ

# はじめに
いつもはwinpcでローカルリポジトリを作ってソースを作ってpushするというのを一方通行で行っていてこれは問題ない。ところがふとしたときにcloneから始まる必要があったときに小一時間沼にハマった。

# 結論
gitコマンドならpushできるけどvscodeの機能からのpushはできない。なんじゃそりゃ～

# まずプライベートリポジトリを手で作った
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/94562/b1241fb4-18e1-c5ca-671e-5e09798c3584.png)

# 鍵を作ります
https://help.github.com/en/github/authenticating-to-github/adding-a-new-ssh-key-to-your-github-account
ここに鍵作るよって言われるのでいいよってEnter押す

```text:鍵作成
vscode> ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
  Generating public/private rsa key pair.
  Enter file in which to save the key (C:\Users\yoshi/.ssh/id_rsa):
```
```text:鍵がすでにある場合
  Overwrite (y/n)? y
```
```text:パスフレーズ（パスワードの長い版）を入れてね。確認のためにもう一回入れてね
  Enter passphrase (empty for no passphrase): 
  Enter same passphrase again:
```

# 確認
たったいま秘密鍵と公開鍵が作成された
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/94562/c183bd62-2eb3-5769-0890-f490194edd92.png)


# githubに「公開鍵」を登録します
鍵登録画面を開いて
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/94562/e0624a78-3beb-858e-ffb7-96dee15a2abb.png)
メモ帳で開いて
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/94562/fc03123f-9977-6658-1527-7f4d20f57643.png)
ぜんぶコピペ えいっ！
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/94562/ff386374-1fe4-b452-97e9-328f6f620acd.png)
おっ、できたな
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/94562/ecb54688-53e7-b1df-4214-dcd6181bc93f.png)

# 確認
おっけー

```
vscode> ssh -T git@github.com
  Enter passphrase for key 'C:\Users\yoshi/.ssh/id_rsa':
  Hi duri0214! You've successfully authenticated, but GitHub does not provide shell access.
```

# clone
手で作ったプライベートリポジトリのURLをcopy
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/94562/f41393e0-5de3-3cd2-e672-21b91abb76f9.png)

```text:clone
(cloneしたい場所に移動)
vscode> cd D:\OneDrive\ドキュメント\Project

(clone)
vscode> git clone git@github.com:duri0214/keel1.git
  Cloning into 'keel1'...
  Enter passphrase for key '/c/Users/yoshi/.ssh/id_rsa': 
  remote: Enumerating objects: 73, done.
  remote: Counting objects: 100% (73/73), done.
  remote: Compressing objects: 100% (67/67), done.
  remote: Total 73 (delta 18), reused 6 (delta 1), pack-reused 0
  Receiving objects: 100% (73/73), 174.45 KiB | 530.00 KiB/s, done.
  Resolving deltas: 100% (18/18), done.
```

# 確認
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/94562/9095e407-c00e-eaa4-87b7-ff1220d11ba9.png)
![image.png](https://qiita-image-store.s3.amazonaws.com/0/94562/b5ad22f6-93f3-6556-b4dc-074ba44f28c8.png)

# ファイルに変更を加える
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/94562/2e4b9824-1f4a-067b-7cb6-e5f1a7069cfa.png)
![image.png](https://qiita-image-store.s3.amazonaws.com/0/94562/b5ad22f6-93f3-6556-b4dc-074ba44f28c8.png)

# staging and commit and push
staging
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/94562/18901cf9-6c81-d08e-0cf8-2e17b05c85ad.png)
commit
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/94562/4c6183d9-adc6-400e-ed8b-a74fc8aeab8f.png)
push
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/94562/201000bb-bba9-69cd-5044-c69864813895.png)
ぬわー！
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/94562/2806492e-a7a6-39b1-9f96-ac4ba86ccc6a.png)
## ※pushできない
https://help.github.com/en/github/authenticating-to-github/error-permission-denied-publickey
鍵登録しろとかいろんなところにいろいろ書いてあるんだけどさ...

## gitコマンドだと通る
what's !?

```
(pushしたい場所に移動して）
vscode\Project> cd keel1

(push!)
vscode\Project\keel1> git push

  Enter passphrase for key '/c/Users/yoshi/.ssh/id_rsa':
  Enumerating objects: 5, done.
  Counting objects: 100% (5/5), done.
  Delta compression using up to 6 threads
  Compressing objects: 100% (2/2), done.
  Writing objects: 100% (3/3), 260 bytes | 260.00 KiB/s, done.
  Total 3 (delta 1), reused 0 (delta 0)
  remote: Resolving deltas: 100% (1/1), completed with 1 local object.
  To github.com:duri0214/keel1.git
     3c9f997..cd87757  master -> master
```

## 解決！
[俺はただwindows 10のvscodeからgit pushしたかっただけ](http://ajishixo.hatenablog.com/entry/2019/03/23/133206)
vscodeからgit pushするときにOpenSSHを使うため、以下を記述。

```text:C/Users/(username)/.gitconfig
[core]
        sshCommand = C:/Windows/System32/OpenSSH/ssh.exe
```

[Win10でssh-addがError connecting to agent: No such file or directory](https://qiita.com/yuta0801/items/d65f1fc3115773861283)
PowerShellを管理者権限で開き、以下を実行（青い画面のコンソールだよ）

```text
Set-Service -Name ssh-agent -StartupType Manual
Start-Service ssh-agent
```

Windows起動時に毎回ssh-add.exeで秘密鍵をssh-agent.exeに登録する
コマンドプロンプトを起動し以下を実行。

```
C:\Users\ajishixo>ssh-add C:\Users\<username>\id_rsa
Enter passphrase for C:\Users\<username>\id_rsa:
Identity added: C:\Users\<username>\id_rsa (C:\Users\<username>\id_rsa)
```