第一次上传代码到gitee

时间:2023-12-20 15:22:44
  • 初始化
git init
  • 添加文件到本地仓库
git add .
  • 提交文件到本地仓库
git remote add origin 仓库地址
  • 拉去远程仓库代码
git pull origin master
  • 推送代码到远程仓库
git push origin master
  • 然后会出现错误
To https://gitee.com/wuzhiqi123/demo-spring-batch.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'https://gitee.com/wuzhiqi123/demo-spring-batch.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
  • 问题:拒绝合并无关的历史

  • 方案

 git pull origin master --allow-unrelated-histories
  • 重复上面操作
git add .
git commit -m 'init'
git push origin master