Git 使用指南
返回首页
技术分享
2025-12-20
配置git
git config --global user.name "你的用户名"
git config --global user.email "你的邮箱"
初始化仓库
git init
放到暂存区
git add .
把文件放到本地git仓库
git commit -m "描述"
关联仓库
git remote add origin https://xxx/.git
如果远程仓库非空
git pull origin main --allow-unrelated-histories
提交到远程git仓库
git push -u origin main
后续git push即可
git ssh key
1.生成 SSH 密钥(替换为你的 GitHub 邮箱)
ssh-keygen -t ed25519 -C "你的GitHub注册邮箱@xxx.com"
2.查看sshkey
type C:\Users\你的用户名\.ssh\id_ed25519.pub
3.登录 GitHub → 点击右上角头像 → Settings → SSH and GPG keys → New SSH key;
4.Title 填任意名称(比如 Windows),Key 粘贴刚才复制的公钥内容,点击 Add SSH key。
5.修改本地仓库的远程地址为 SSH 方式
git remote remove origin
# 添加 SSH 格式的远程地址(替换为你的仓库)
git remote add origin git@github.com:Tao-stu/blog.git
# 验证远程地址是否正确
git remote -v