配置成功可以克隆项目,但是git push需要输入账号密码,输入账号密码以后还是提交不成功,报错
remote: <CH.00905401> HTTP Basic: Access denied.
remote: The password-based authentication of Git has been removed.
Please use your personal access token instead of the password.
Request-id is Eacy95FgmE.
fatal: Authentication failed for 'https://gitcode.com
说明:
-
git push 时用的是 HTTPS 地址(
https://gitcode.com/...) -
GitCode 已经 禁止了密码认证,必须用 个人访问令牌(Personal Access Token,PAT) 代替密码
-
这也解释了为什么克隆用 SSH 成功,但推送用 HTTPS 时失败了
正确的解决方案(推荐)
1️⃣ 确保用的是 SSH 远程地址
打开项目文件夹,执行:
git remote -v
如果你看到的地址是以 https:// 开头,说明远程仓库是 HTTPS 方式。
2️⃣ 修改远程地址为 SSH 方式
假设 SSH 地址是:
git@gitcode.com:用户名/仓库名.git
执行:
git remote set-url origin git@gitcode.com:用户名/仓库名.git
然后再执行:
git remote -v
确认地址变成 SSH 了。
3️⃣ 推送代码(SSH 不会再要账号密码)
git push origin main
如果非要用 HTTPS 推送,也必须用 PAT(个人访问令牌)代替密码:
-
登录 GitCode 账号
-
创建个人访问令牌(PAT)
-
推送时账号输入用户名,密码输入该令牌
不过用 SSH 方式更方便,不用每次输密码。


3560

被折叠的 条评论
为什么被折叠?



