git push origin master 出来なかったが解決した


# はじめに

git push origin master 出来なかったが解決した。


# 環境の情報
OS
macOS Big Sur 11.3

# 注意
最新の状態を確認して下さい。

# 参考さまはこちら
https://docs.github.com/ja/enterprise-cloud@latest/get-started/getting-started-with-git/about-remote-repositories
https://docs.github.com/ja/enterprise-cloud@latest/repositories/creating-and-managing-repositories/troubleshooting-cloning-errors
https://docs.github.com/en/get-started/getting-started-with-git/managing-remote-repositories
https://trios.pro/github-403-error/

# 最終更新日
2023年7月12日

# 結論

SSHで繋ごう！


# 状況

（不要な手順もあるかもですが、一応残しておきます。）

コミットをした。

```
my-project 
```
```
% git commit -m "new project "
[master XXXXXX] new project
 % git status          
On branch master
```

問題なくできた。

↓

```
% git push origin master 
fatal: 'origin' does not appear to be a git repository
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
```
「origin」は git リポジトリではないようです。
リモート リポジトリから読み取ることができませんでした。
と出る。

↓

```
 % git remote add orign https://github.com/user/repo.git
```

追加。

↓

```
 % git push origin master
fatal: 'origin' does not appear to be a git repository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

```
およ。

↓

```
% git remote -v
orign	https://github.com/user/repo.git (fetch)
orign	https://github.com/user/repo.git (push)
```
見に行くが、特に問題なさそうである。

↓

```
% cat ~/.ssh/id_rsa.pub
ssh-rsa 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

```
鍵も確認。

↓

```
% cd ~/.ssh       
```

↓

```
.ssh % ls
id_rsa		id_rsa.pub	known_hosts
```

↓

```
.ssh % vi config       
.ssh % cat config
Host github
 HostName github.com
 IdentityFile ~/.ssh/id_rsa
 User git
```
Github上にも確認したが、問題なく。

↓

```
% cd my-project 
% git push origin master 
fatal: 'origin' does not appear to be a git repository
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
```
むむ？

↓

```
% git remote add origin 
https://github.com/user/repo.git
```


↓

```
% git push origin master 
Username for 'https://github.com': user
Password for 'https://user@github.com': pass
remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/user/repo.git'

```

↓

```
トークンなども設定してみたものの
```

↓

```
 % git push origin master 
Username for 'https://github.com': user
Password for 'https://user@github.com': pass
remote: Permission to user/repo.git denied to user.
fatal: unable to access 
'https://github.com/user/repo.git': The requested URL returned error: 403
```

↓

```
% git config --global user.name "user"
% git config --global user.email "xxxx@xxx.com"
```
ユーザーの設定などする。

↓

```
% git config -l
user.name=user
user.email=xxxx@xxx.com
```

↓

```
同じエラー
```

↓

```
色々読むと、SSHで繋いだ方が良さそうだと気づいた。
```

↓

```
% ssh -T git@github.com
Hi user! You've successfully authenticated, but GitHub does not provide shell access.
```


↓

```
% git remote set-url origin git@github.com:
user/komaroot.git
```


↓

```
% git remote -v
orign	https://github.com/user/repo.git (fetch)
orign	https://github.com/user/repo.git (push)
```


↓

```
 % git push origin master 
Enumerating objects: 52, done.
Counting objects: 100% (52/52), done.
```




# 終わり

GitHub、最近仕様が変わったっぽいのでハマったらSSHで繋いだ方が良さそうです。