如何處理 git使用中push報錯

間隔了一段時間未往gitlab上push文件,近期使用時,發現push時報錯,這裏記錄下解決處理的方法。html

錯誤一:linux

[root@361way shell]# git push
warning: push.default is unset; its implicit value is changing in
Git 2.0 from 'matching' to 'simple'. To squelch this message
and maintain the current behavior after the default changes, use:
git config --global push.default matching
To squelch this message and adopt the new behavior now, use:
git config --global push.default simple
See 'git help config' and search for 'push.default' for further information.
(the 'simple' mode was introduced in Git 1.7.11. Use the similar mode
'current' instead of 'simple' if you sometimes use older versions of Git)

放"狗"查詢後,得知‘matching’ 參數是 Git 1.x 的默認行爲,其意是若是你執行 git push 但沒有指定分支,它將 push 全部你本地的分支到遠程倉庫中對應匹配的分支。而 Git 2.x 默認的是 simple,意味着執行 git push 沒有指定分支時,只有當前分支會被 push 到你使用 git pull 獲取的代碼。鍵入以下命令:git

[root@361way shell]# git config --global push.default matching

錯誤二:github

[root@361way shell]# git push -u origin master
To https://361way:mypassword@github.com/361way/shell.git
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'https://361way:mypassword@github.com/361way/shell.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 merge the remote changes (e.g.,
hint: 'git pull') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

再次push,發現又有報錯,根據報錯內容,大體瞭解的狀況是,本地和遠端的內容可能不一致,建議git pull 一份,再push到romte 。因爲平時有些修改會在阿里雲服務器上修改過的懶得push到遠端同步,因此本地和遠端的不一致也是有可能的。即然不一致,以阿里雲上保存的爲準吧,強制同步下。shell

[root@361way shell]# git push -u origin master --force

強制同步,發現能夠正常同步內容到github上,並且後面再加文件進行同步,發現也未出現報錯了。服務器

原文來自:https://www.linuxprobe.com/git-push-error.htmlgitlab

相關文章
相關標籤/搜索