在本地與遠程新建倉庫並關聯后,初次push可能會遇到以下問題
- $ git push -u origin master
- To https://gitee.com/xxxx/gittest.git
- ! [rejected] master -> master (fetch first)
- error: failed to push some refs to 'https://gitee.com/xxxx/gittest.git'
- hint: Updates were rejected because the remote contains work that you do
- hint: not have locally. This is usually caused by another repository pushing
- hint: to the same ref. You may want to first integrate the remote changes
- hint: (e.g., 'git pull ...') before pushing again.
- hint: See the 'Note about fast-forwards' in 'git push --help' for details.
原因是因為遠程倉庫有一些文件而本地沒有,通常是在遠程建立倉庫時有一些初始化文件比如Readme License 等,並且直接pull會提示warning: no common commits
,對於此類問題可以采用兩種解決辦法
1.git push -f 強制將本地文件推送至遠程,這樣會將遠程倉庫的已有的文件清掉
2. git pull origin master –allow-unrelated-histories 使用此命令告訴 git 允許不相關歷史合並 這樣就能把遠程文件拉取回來。執行此命令后會有一個提示,要求說明為何要講兩個不相關的分支合並,輸入信息后保存即可。
拉取完不同的文件之后再執行git push -u origin master
命令即可push成功。
建議使用第二種辦法
- Merge branch 'master' of https://gitee.com/xxxx/gittest.git
- # Please enter a commit message to explain why this merge is necessary,
- # especially if it merges an updated upstream into a topic branch.
- #
- # Lines starting with '#' will be ignored, and an empty message aborts
- # the commit.
- Merge made by the 'recursive' strategy.
- .gitignore | 66 ++++++++++++
- LICENSE | 339 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- README.en.md | 36 +++++++
- README.md | 37 +++++++
- 4 files changed, 478 insertions(+)
- create mode 100644 .gitignore
- create mode 100644 LICENSE
- create mode 100644 README.en.md
- create mode 100644 README.md