fatal:Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.
出现这个问题的原因是因为没有在github账号添加SSH key。
解决这个问题的办法是:
- 在终端输入
ssh-keygen -t rsa -C "username" (注:username为你git上的用户名)
执行成功,返回
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/username/.ssh/id_rsa):
这里的username是你电脑上的用户名
Enter passphrase (empty for no passphrase):
直接回车
Enter same passphrase again:
回车
Your identification has been saved in /Users/username/.ssh/id_rsa.
Your public key has been saved in /Users/username/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:ICRwoBNoU6kOLEexOwwR0yFgUXC1yChs5otSeAH2/+4 username
The key's randomart image is:
+---[RSA 2048]----+
|&XX+. |
|XB=. . | 一堆
|B=+... |
|BB.o.. . |
|=o . S |
|.+.. . |
|o. . |
|. . |
| .E |
+----[SHA256]-----+
最后执行cat命令查看文件的内容:
cat /Users/username/.ssh/id_rsa.pub
这时候会看见
ssh-rsa AAAAB3Nza吧啦吧啦
复制到git的add SSH key里面进行添加
cd 到工程目录
git init
git remote add origin git@地址.git
如果出现fatal: remote origin already exists.
输入 git remote rm origin
git add .
git commit -m "initial commit"
git push -u origin master