← 返回AI变现
🌐 其他

如何在服务器上克隆、pull、push GitHub私有项目

来源:掘金 · 发布于 2026-08-22 12:52:56
如何在服务器上克隆、pull、
本文详解GitHub`git clone`认证失败的解决方案:因密码认证已废弃,需改用Personal Access Token(推荐fine-grained类型),涵盖创建、权限配置(如repo读写

如何在服务器上克隆、pull、push GitHub私有项目

诸神缄默不语 2026-08-22 0 阅读2分钟

诸神缄默不语-个人技术博文与视频目录

我是在本地电脑上修改、开发应用代码,然后想推送到GitHub私有仓库,并在服务器上直接克隆、编辑、更新对应的项目。
现在GitHub搞2FA认证了,我是直接用谷歌浏览器存的Passkey。这块我就不介绍了。总之本文就只讲personal access token的事:

我执行git clone命令后,会提示让我输入GitHub账号密码。以前是可以直接输入账号密码的,但是现在我输入账密后它还是显示克隆失败,并显示:

(2024年12月的效果:)

Cloning into 'folder_name'...
Username for 'https://github.com': user_name
Password for 'https://user_name@github.com': 
remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/user_name/folder_name.git/'

(2026年8月的效果:)

remote: Invalid username or token. Password authentication is not supported for Git operations.
fatal: Authentication failed for 'https://github.com/user_name/folder_name.git/'

也就是说现在不支持仅用账号密码来克隆GitHub项目了,解决方案是在输入密码时改为输入personal access token。获取personal access token的方式:

  1. 进入github.com/settings/pe… 现在personal access token分成fine-grained和classic两种。
    效果差不多,我就只介绍fine-grained token了。
  2. 创建token:
    generate new token
  3. 指定token名称(会在token列表中看到,方便明确哪个token是拿来干什么事的)、token描述、过期时间、repository范围和权限(想要正常执行clone、pull等操作就得给代码读写权限)。
    这个resource owner我也不知道除了自己还能选谁,我就是给自己用的,所以还没有仔细研究。 界面(上)
    界面(repository范围)
    界面(权限)
  4. 生成personal access token后点击复制即可(注意这个token只会生成一次,在token详情界面中也不能复制)
    在token详情界面中可以续期。