https访问github仓库失败问题解决
问题描述
使用https协议推送本地的git仓库代码到github时出现如下错误:
$ git push -u origin main
remote: Support for password authentication was removed on August 13, 2021. Please use a personal access token instead.
remote: Please see https://github.blog/2020-12-15-token-authentication-requirements-for-git-operations/ for more information.
fatal: Authentication failed for 'https://github.com/lxyjrx/freertos_stm32_sample.git/'
提示认证失败,意思大概是原来的密码认证方式已经被淘汰,需要使用个人访问令牌来访问。
解决办法
在github上面创建个人访问令牌(token),然后使用这个令牌来访问github仓库,方法步骤如下:
1、登录github,点击设置,如下图示:
2、点击开发者设置
3、点击个人访问令牌,然后选择创建令牌,
4、设置令牌的有效期和权限,
5、生成令牌,记住令牌
因为该网页一刷新,令牌就看不到了,所以要记住这个令牌。
6、使用令牌登录github,提交本地代码
我们可以通过每次输入github用户名和令牌来访问github仓库;也可以输入以下命令来避免每次都要输入用户名和令牌:
git remote set-url origin https://<your_token>@github.com/<USERNAME>/<REPO>.git
<your_token>:是指你的令牌
<USERNAME>:是指github的用户名
<REPO>:是指仓库的名称
示例如下:
guest1@DESKTOP-zzc MINGW64 /e/mdk_arm/my_prj/sample2_project (main)
$ git remote set-url origin https://ghp_CtaMTCDKt4t6a3tZy1234FiXB8567t0YrMUH@github.com/lxyjrx/freertos_stm32_sample.git
guest1@DESKTOP-zzc MINGW64 /e/mdk_arm/my_prj/sample2_project (main)
$ git push -u origin main
Enumerating objects: 152, done.
Counting objects: 100% (152/152), done.
Delta compression using up to 12 threads
Compressing objects: 100% (149/149), done.
Writing objects: 100% (152/152), 19.87 MiB | 74.00 KiB/s, done.
Total 152 (delta 32), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (32/32), done.
To https://github.com/lxyjrx/freertos_stm32_sample.git
* [new branch] main -> main
Branch 'main' set up to track remote branch 'main' from 'origin'.
总结
很久没有用http登录github了,突然遇到这个问题,记录以下解决的办法,也供大家参考;
方法还是有很多的,需要大家慢慢去探索。
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 【.NET】调用本地 Deepseek 模型
· CSnakes vs Python.NET:高效嵌入与灵活互通的跨语言方案对比
· DeepSeek “源神”启动!「GitHub 热点速览」
· 我与微信审核的“相爱相杀”看个人小程序副业
· Plotly.NET 一个为 .NET 打造的强大开源交互式图表库