如何在新机器上设置github完成内容git push

如果你在一台新的机器上git pull 仓库,完成修改,然后git push,会发现下面错误:

bash 复制代码
Username for 'https://github.com': xiaomaolv
Password for 'https://xiaomaolvgithub.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/xiaomaolv/'

这是因为你第一次在这台机器上操作,需要设置.

方案1 ssh

首先在本地机器生成ssh,如果已经有可以掠过:

bash 复制代码
 $ ssh-keygen -t rsa -C "xiaomaolv@xjblll-tech.comm"
Generating public/private rsa key pair.
Enter file in which to save the key (/home/xiaomaolv/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/xiaomaolv/.ssh/id_rsa
Your public key has been saved in /home/xiaomaolv/.ssh/id_rsa.pub
The key fingerprint is:
SHA256:onw16/MR30zP4u+dUmxKdnvtzLZ5jdU5iN4Qb4dIaj4 xiaomaolv@xjblll-tech.comm
The key's randomart image is:
+---[RSA 3072]----+
|                 |
|                 |
|                 |
|           o     |
|      . S + = = o|
|   . . o = * @ @o|
|    o . + o B XoB|
|     . ..E o =.=X|
|        .oo   oO@|
+----[SHA256]-----+

然后copy ssh-rsa 到github网页中的SSH and GPG keys中

bash 复制代码
cat /home/xiaomaolv/.ssh/id_rsa.pub 
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDLu5oKyIQjFXv4JPNZHlStLLcN+5uGR7yaacuRXJ4/uust0z6AXAAm/8X9pU3CMBbFbkgNSsBngmFJcXUMOZTrTIjcIMFAjbZwO7/gdY9XoiiKG+0zqKeCTzqgJsBBvaZQwihil9r3gLahgJMFzZhS457Zwu35xCwD7CKT5BBxD96oTCDgn88rCFLRwzQ7bA8fyLvKvKkJLbRDqbfLv3XkbsyAfJcWtTgLbfGe76pxiPeICYeIBrJDsVG0TwfThS+vlF4Dq8rNL3k6QAD59TRYsqlqY5LobeQy1sSkPFK4Xa+PAgeVydx4O3M91/V46HF3oCI2MYi505HnxQ19KykqEkShVzuaWXamGP3QMU4ZJzww88W84qkYvNW4yO/PWafoQbgZj3qVjXZkp+2WBd112uz+jwhzB/lz5i/uMyo8TKCVy3lYubiIFhswVhn6NicsMbMKAn+qWbebxquL+3eEWt14s4/lMIXU5xH6KVNlJEGH/0EkBrylVPZA0/UTyb8= xiaomaolv@xjblll-tech.comm

打开github网页,并添加:

本地执行测试

如果出现下面信息,则说明成功了。

bash 复制代码
$ ssh -T git@github.com
The authenticity of host 'github.com (20.205.243.166)' can't be established.
ECDSA key fingerprint is SHA256:p2QAMXNIC1TJYWeIOttrVc98/R1BUFWu3/LiyKgUfQM.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'github.com,20.205.243.166' (ECDSA) to the list of known hosts.
Hi ! You've successfully authenticated, but GitHub does not provide shell access

切换认证方式:

bash 复制代码
# 切换到 SSH
git remote set-url origin git@github.com:EnflameTechnology/FFmpeg-GCU.git

git push

bash 复制代码
$ git push
Enumerating objects: 17, done.
Counting objects: 100% (17/17), done.
Delta compression using up to 16 threads
Compressing objects: 100% (9/9), done.
Writing objects: 100% (9/9), 947 bytes | 947.00 KiB/s, done.
Total 9 (delta 7), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (7/7), completed with 7 local objects.
To github.com:EnflameTechnology/FFmpeg-GCU.git
   3ef21d7..b68a39c  main -> main

note: 如果在这个阶段还是出现permission not allowed ,那么就要去找github 仓库管理员要权限了。

http方式

除了上面提供的ssh方式,github还提供了第二种方式http方式

执行的命令如下,核心是如何获取TOKEN,

bash 复制代码
# 或切换到 PAT
git remote set-url origin https://<TOKEN>@github.com/EnflameTechnology/FFmpeg-GCU.git

其中是:

GitHub → Settings → Developer settings → Personal access tokens

TOKEN同时会发邮件到邮箱

总结:

两种方式git push

相关推荐
徐小夕8 小时前
再也不怕看不懂 GitHub 代码!这款AI开源项目,一键生成交互架构图
前端·算法·github
兰德里的折磨55011 小时前
使用git提交时出现了报错,新手不会的可以参考一下。
git
一点一木11 小时前
🚀 2025 年 07 月 GitHub 十大热门项目排行榜 🔥
前端·人工智能·github
qianmoQ11 小时前
GitHub 趋势日报 (2025年07月28日)
github
一块plus12 小时前
1,000 万 DOT 奖励,JAM Prize 邀你共建 Polkadot 下一代基础设施!
javascript·后端·github
JavaDog程序狗13 小时前
【教程】以程序员张三的故事,沉浸式详解Git常用命令
git
白衣鸽子14 小时前
Git Commit Message规范:Angular Convention
git
MicrosoftReactor16 小时前
技术速递|GitHub Copilot 的 Agent 模式现已全面上线 JetBrains、Eclipse 和 Xcode!
ai·github·copilot
坐吃山猪19 小时前
GitPython03-项目setup编译
git·python·setup
liux35281 天前
DevOps 实践指南:Git 版本控制从入门到精通
git