git fetch origin branchName
报错:
Permission denied (publickey,password).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
原因是没有设置 ssh key
三步解决:
1、生成 ssh key
1. cd ~/.ssh
2. ssh-keygen -t rsa -b 2048 -C "你的邮箱"
3. Enter file in which to save the key (Users/username/.ssh/id_rsa): 这步提示输入文件名称,直接回车表示默认文件名id_rsa,可以自定义文件名,如 custom_id_rsa
4. Enter passphrase (empty for no passphrase):输入密码,可以为空
5. 提示再次确认密码
6. 完成,拷贝 id_rsa.pub 的内容进行下一步
2、拷贝 id_rsa.pub 的内容添加到 gitlab 的 Settings - “SSH Keys” 中
3、本地添加 ssh 秘钥
ssh-add id_rsa
Identity added: id_rsa (xxx@xxx.cn)
再次执行 git fetch origin branchName
成功.