- 初始化:
git init
- 把项目添加到本地仓储:
git add . git commit -am "备注"
- 添加远程地址
git remote add origin https://gitee.com/xxx/xxx.git
- 本地分支和远程分支 建立连接
git branch --set-upstream-to=origin/master master
- 因为远程仓库是刚创建的,本地仓库和远程仓库有不同的开始点【没有共同的commit】,需要拉取代码
git pull origin master --allow-unrelated-histories
- 异常就是由【4/5】导致的
$ git push To https://gitee.com/xxx/xxx.git ! [rejected] master -> master (non-fast-forward) error: failed to push some refs to 'https://gitee.com/xxx/xxx.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.