本地代码上传到Github
先在 GitHub 上创建一个空的 Repository(仓库),创建时不要勾选“Initialize this repository with a README”等选项。保持仓库为空,可以避免和本地代码产生冲突。
然后在本地代码库运行 git init,初始化本地 Git 仓库。
然后执行git remote add origin https://github.com/XXX/YYY.git
得到报错信息error: remote origin already exists
运行 git remote -v
origin https://gitee.com/y_project/YYY.git (fetch)
origin https://gitee.com/y_project/YYY.git (push)这说明 origin 已经被配置了,它现在指向 Gitee
现在重新指向
git remote set-url origin https://github.com/XXX/YYY.git然后再运行 git remote -v 确认。
现在可以推送代码,使用
git push -u origin main
# or
git push -u origin master比如
$ git push -u origin main
error: src refspec main does not match any
error: failed to push some refs to 'https://github.com/XXX/YYY.git'说明本地没有叫main的 local branch,运行git branch来查看
$ git branch
* master然后选择合适的方式推送,之后运行git status查看状态。
参考资料:使用Git上传本地代码到GitHub
评论已关闭