一文搞定 GitHub 私有仓库配置与代码上传

一、初始化本地仓库

cd ~/your-robot-project
git init
git add .
git commit -m "Initial commit"

二、配置 Git 身份

git config --global user.name "你的名字"
git config --global user.email "你的邮箱@xxx.com"

三、使用 SSH 免密推送

ssh-keygen -t ed25519 -C "your_email@example.com"
# 按回车默认保存,不设密码
cat ~/.ssh/id_ed25519.pub  # 复制输出内容

去 GitHub → Settings → SSH and GPG keys → 新建 SSH Key → 粘贴

验证是否成功

ssh -T git@github.com
# 看到 "Hi 你的用户名! You've successfully authenticated" 就对了!

四、关联远程仓库

git remote add origin git@github.com:你的用户名/仓库名.git
git branch -M main                                                 #将本地分支更改为main               
git push -u origin main                                           #推送到远程

如果提示 fetch first,说明远程有 README,执行:

git pull origin main --allow-unrelated-histories
git push -u origin main

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值