解决 error: failed to push some refs to 'https://github.com/

简介: Resolve error: failed to push some refs to \'https://github.com/

Resolve error: failed to push some refs to \'https://github.com/

报错:

! [rejected] main -> main (fetch first)
error: failed to push some refs to ' https://github.com/XXX.git'

原因:远程库和本地库不一致。通常出现在初始化仓库有readme而本地没有等情况。

提示: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.

解决方法:

git pull --rebase origin master

原理:

把远程库中的更新合并到本地库中,–-rebase的作用是取消掉本地库中刚刚的commit,并把他们接到更新后的版本库之中。然后再进行push即可。

git pull -–rebase origin master 操作,意为先取消commit记录,并且把它们临时保存为补丁(patch)(这些补丁在”.git/rebase”目录中),之后同步远程库到本地,最后合并补丁到本地库之中。

注意:距离上次push提交至今,在本地库commit的记录均暂存为patch。

目录
相关文章
|
4天前
|
网络安全 开发工具 git
解决fatal:remote error:You can’t push to git://github.com/username/*.g
通过上述诊断与修复步骤,绝大多数的推送错误都能得到有效解决,确保您的Git工作流顺畅无阻。
7 1
verbose stack FetchError: request to https://registry.npm.taobao.org/md-editor-v3 failed, reason: ce
这篇文章描述了在安装npm包`md-editor-v3`时遇到的淘宝镜像证书过期问题,并提供了解决方案,即通过切换npm镜像源到`https://registry.npmmirror.com/`来解决安装失败的问题。
verbose stack FetchError: request to https://registry.npm.taobao.org/md-editor-v3 failed, reason: ce
|
3月前
|
Java Spring
成功解决Initialization failed for ‘https://start.spring.io‘ Please check URL, network and proxy settings
这篇文章提供了解决Spring Initializr网站初始化失败问题的方法,包括检查URL、网络和代理设置。
成功解决Initialization failed for ‘https://start.spring.io‘ Please check URL, network and proxy settings
|
2月前
|
Shell 网络安全 开发工具
fatal: unable to access 'https://github.com/wolfcw/libfaketime.git/': Encountered end of file
fatal: unable to access 'https://github.com/wolfcw/libfaketime.git/': Encountered end of file
|
2月前
|
测试技术 API
8-20|https://gitlab.xx.com/api/v4/projects/4/trigger/pipeline Request failed 状态码400
8-20|https://gitlab.xx.com/api/v4/projects/4/trigger/pipeline Request failed 状态码400
|
3月前
|
JavaScript
request to https://registry.npm.taobao.org/cnpm failed, reason: certificate has expired
request to https://registry.npm.taobao.org/cnpm failed, reason: certificate has expired
91 2
|
5月前
|
开发工具 git
【已解决】error: failed to push some refs to ‘git@github.com:BATdalao/Github-green.git‘
【已解决】error: failed to push some refs to ‘git@github.com:BATdalao/Github-green.git‘
Get “https://npm.taobao.org/mirrors/node/latest/SHASUMS256.txt“: tls: failed to verify certificate:
Get “https://npm.taobao.org/mirrors/node/latest/SHASUMS256.txt“: tls: failed to verify certificate:
|
2月前
|
监控 安全 搜索推荐
设置 HTTPS 协议以确保数据传输的安全性
设置 HTTPS 协议以确保数据传输的安全性
|
25天前
|
安全 网络协议 算法
HTTPS网络通信协议揭秘:WEB网站安全的关键技术
HTTPS网络通信协议揭秘:WEB网站安全的关键技术
129 4
HTTPS网络通信协议揭秘:WEB网站安全的关键技术