工作的时候遇到的一个问题,当切换用户的时候,使用git pull下拉到本地代码时候,git提醒:
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
首先确保用户名切换成功, 可使用
git config -–global user.name "xxx"
git config –-global user.email "xxx@xxx.com"
并且自己的ssh key 已经添加到git hub 上。
为什么用户切换成功,ssh key设置成功, 还会发生这个问题呢。
---- 是因为你clone 代码的时候使用旳是上一个用户的信息。所以你只有将用户的相关账户信息改正才可。
查看方法 $ git config --list
remote.origin.url=ssh://xxx@xxxxxx
中显示ssh上传相关project信息。
修改成自己的账户(用户名)即可。
修改方法:
进入本地clone的项目。
project \ .git \ config
[remote "origin"]
url = ssh://xxx@xxxxx/project
fetch = +refs/heads/*:refs/remotes/origin/*
将其中的URL改变成自己的就OK啦。