如何在新机器上设置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

相关推荐
极光技术熊9 小时前
Spring AI 从入门到精通:构建你的 AI 开发知识体系
后端·github
用户394839510755310 小时前
怎么让我的 Agent 真正"懂"我?——关于记忆、经验学习与预测的一些真实体验
github
远航_16 小时前
git submodule
前端·后端·github
fthux18 小时前
如果你用 Mac,那你可能需要 Noti Shift
macos·开源·github
程序员天天困1 天前
Loop Engineering 实战:/goal 命令让 AI 自己写完整项目
github
徐小夕1 天前
我们开源了一款“框架无关”的思维导图编辑器,3分钟集成到任意系统
前端·javascript·github
小爷毛毛_卓寿杰1 天前
我把 397B 的「Agentic 大脑」塞进了 Xinference,一键部署 Nex-N2
人工智能·架构·github
小爷毛毛_卓寿杰2 天前
我把一个 3B 模型塞进了 Xinference,然后它干掉了 DeepSeek V3.2
人工智能·开源·github
凌奕2 天前
别用文档约束你的 Agent:聊聊 Agent 开发流程的思想
llm·github·agent
和你看星星2 天前
Git rerere:让重复冲突只解决一次
git