Mac之Git账号的坑

Permission to xxx/xxxxx.git denied to username.

之前使用mac终端中的git时,输入了用户名和密码,现在换了新的用户名密码后,clone下来的代码,修改后push 却提示 remote: Permission to marspie/marspie-demo.git denied to yaonew.
fatal: unable to access ‘https://github.com/marspie/marspie-demo.git/': The requested URL returned error: 403
其中yaonew是我第一次使用的用户名,现在已经使用了新的用户了。尝试重新 ssh-keygen 生成密钥,github添加新的密钥,无果。

经过网络搜索,有提出同样问题的,但是回复寥寥无几且没有能真正解决问题的,于是变化思路查找:Mac多Git账号配置,找到了一个帖子:http://suqianghotel.com/2016/09/13/mac-mulit-git-account-config/ 在文章的末尾找到了GitHub 官网的帮助文档:
GitHub help

Updating credentials from the OSX Keychain

You’ll need to update your saved username and password in the git-credential-osxkeychain helper if you change your password or username on GitHub.

Updating your credentials via Keychain Access

  1. In Finder, search for the Keychain Access app.
  2. In Keychain Access, search for github.com.
  3. Find the “internet password” entry for github.com.
  4. Edit or delete the entry accordingly.

Deleting your credentials via the command line

Through the command line, you can use the credential helper directly to erase the keychain entry.

To do this, type the following command:

$ git credential-osxkeychain erase
host=github.com
protocol=https
[Press Return]

If it’s successful, nothing will print out. To test that it works, try and clone a repository from GitHub. If you are prompted for a password, the keychain entry was deleted.

重新 git push

$ git push origin master
Username for 'https://github.com': marspie
Password for 'https://marspie@github.com': 
Counting objects: 8, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (8/8), done.
Writing objects: 100% (8/8), 628 bytes | 0 bytes/s, done.
Total 8 (delta 5), reused 0 (delta 0)
remote: Resolving deltas: 100% (5/5), completed with 5 local objects.
To https://github.com/marspie/marspie-demo.git
   32fe0cd..0a71a8a  master -> master

OK 搞定, tag!

Alex.Yao wechat
欢迎您扫一扫上面的微信公众号,订阅我的博客!
坚持原创技术分享,您的支持将鼓励我继续创作!