改变wifi环境后MacOS M1下Git遇到的问题

179 阅读1分钟

1. ssh问题

上海lock down74天之后,我从自己家回到父母家,再次使用git命令行遇到报错:

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

stackoverflow找到答案,在此贴一下:

This issue can be caused because sometimes ssh-agent is not persistent across reboots. You should check if ssh-agent has your key added:

ssh-add -l -E md5

if you get the output like:

The agent has no identities.

it means ssh-agent has lost your key. In that case, you simply need to add the identity key again. Something like:

ssh-add ~/.ssh/git_rsa

The error should disappear now!

总结:只要不重新生成,ssh-key是不变的,但移动电脑可能导致ssh-agent会丢失ssh-key,此时需要手动添加一下。

2. 丢失git config问题

遇到用户权限问题,只要运行git config --list检查user.nameuser.email是否丢失,就能找到问题。这次我就遇到了name还在,但email丢失的情况,手动添加email就可以了。

3.# 常见错误 之 error: src refspec xxx does not match any / error: failed to push some refs to

解决方案: 把本地的 master 仓库名称修改为远端的 main

git branch -m oldBranchName newBranchName

然后,push 就好了.