良许Linux教程网 干货合集 使用git push时报错处理方案

使用git push时报错处理方案

git push 命用于从将本地的分支版本上传到远程并合并,但是有些小伙伴在使用此命令时会遇到一些问题,本篇文章为大家列举了常见的两个问题,有需要的小伙伴可以参考一下。

image-20220101122259433

错误一:

[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 获取的代码。键入如下命令

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

错误二:

[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到远端同步,所以本地和远端的不一致也是有可能的。即然不一致,以阿里云上保存的为准吧,强制同步下。

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

强制同步,发现可以正常同步内容到github上,而且后面再加文件进行同步,发现也未出现报错了。

以上就是良许教程网为各位朋友分享的Linu系统相关内容。想要了解更多Linux相关知识记得关注公众号“良许Linux”,或扫描下方二维码进行关注,更多干货等着你 !

img
本文由 良许Linux教程网 发布,可自由转载、引用,但需署名作者且注明文章出处。如转载至微信公众号,请在文末添加作者公众号二维码。
良许

作者: 良许

良许,世界500强企业Linux开发工程师,公众号【良许Linux】的作者,全网拥有超30W粉丝。个人标签:创业者,CSDN学院讲师,副业达人,流量玩家,摄影爱好者。
上一篇
下一篇

发表评论

联系我们

联系我们

公众号:良许Linux

在线咨询: QQ交谈

邮箱: yychuyu@163.com

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

关注微博
返回顶部