下面按最常见场景给你讲一下 Git 远程仓库怎么配置,从零到可用。
git config --global user.name "你的名字"
git config --global user.email "你的邮箱"
示例地址:
git@github.com:username/repo.git
# 或
https://github.com/username/repo.git
git remote add origin git@github.com:username/repo.git
git remote -v
git branch -M main
git push -u origin main
-u 表示设置默认上游分支,以后直接 git push 即可。
git clone git@github.com:username/repo.git
克隆后自动配置好 origin。
git remote set-url origin 新地址
git remote remove origin
git remote add github git@github.com:user/repo.git
git remote add gitee git@gitee.com:user/repo.git
推送:
git push github main
git push gitee main
ssh-keygen -t ed25519 -C "你的邮箱"
cat ~/.ssh/id_ed25519.pub
ssh -T git@github.com
✅ fatal: remote origin already exists
→ 先 git remote remove origin
✅ Permission denied (publickey)
→ 没配置 SSH 或没添加公钥
✅ failed to push some refs
→ 先 git pull,再 git push
如果你告诉我:
我可以直接给你一步一步的具体命令。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。