Git 错误

本文讲述了在初次推送本地代码到git远程仓库时遇到的nothavelocally错误,原因通常是代码不一致。解决方法包括使用git pull进行合并,然后重新git push。详细步骤和提示有助于理解同步过程。
    <link rel="stylesheet" href="https://csdnimg.cn/release/blogv2/dist/mdeditor/css/editerView/ck_htmledit_views-b3c43d3711.css">
            <div id="content_views" class="htmledit_views">
                <pre data-index="0"><code class="language-Kotlin hljs"><ol class="hljs-ln" style="width:100%"><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="1"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">Done</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="2"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">hint: not have locally. This <span class="hljs-keyword">is</span> usually caused <span class="hljs-keyword">by</span> another repository pushing</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="3"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">hint: to the same ref. You may want to first integrate the remote changes</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="4"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">hint: (e.g., <span class="hljs-string">'git pull ...'</span>) before pushing again.</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="5"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">hint: See the <span class="hljs-string">'Note about fast-forwards'</span> <span class="hljs-keyword">in</span> <span class="hljs-string">'git push --help'</span> <span class="hljs-keyword">for</span> details.</div></div></li></ol></code><div class="hljs-button {2}" data-title="复制" onclick="hljs.copyCode(event)"></div></pre> 

为什么会出现这样的错误?:我是新建的项目在git上申请了一个仓库,由于第一次推送本地和远程仓库两者代码文件不同步,因此需要先pull,进行合并然后再进行push。

解决方法:

1、先使用pull命令:

git pull --rebase origin master
 

2、再使用push命令:

git push -u origin master
 

hint: not have locally. This is usually caused by another repository pushing错误

强行让本地分支覆盖远程分支

git push origin master -f
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值