Git Updates were rejected because the remote contains work that you do not

shell 复制代码
09:13:29.529: [bencon-cloud] git -c credential.helper= -c core.quotepath=false -c log.showSignature=false push --progress --porcelain origin refs/heads/master:refs/heads/master --set-upstream
error: failed to push some refs to 'https://.../beacon-cloud.git'
To https://.../beacon-cloud.git
hint: Updates were rejected because the remote contains work that you do not
!	refs/heads/master:refs/heads/master	[rejected] (fetch first)
hint: have locally. This is usually caused by another repository pushing to
Done
hint: the same ref. If you want to integrate the remote changes, use
hint: 'git pull' before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

尝试将本地的 master 分支推送到远程仓库时,推送被拒绝了。这是因为远程仓库中包含了你本地仓库没有的工作或更改。这种情况通常发生在另一个仓库也向同一个分支推送了更改。

解决这个问题的办法是先从远程仓库拉取最新的更改,然后再次尝试推送。你可以按照以下步骤操作:

  1. 执行 Git Pull :首先运行 git pull origin master 命令来拉取并合并远程仓库中的最新更改到你的本地仓库。这可能会导致需要手动解决一些冲突。

    sh 复制代码
    git pull origin master
  2. 解决可能的冲突:如果有任何冲突发生,在Git提示的文件中找到冲突的地方,根据需要解决这些冲突,并标记为已解决(通过Git添加这些文件)。

  3. 提交解决冲突后的更改:如果你解决了任何冲突,请确保将这些更改提交。

    sh 复制代码
    git commit -am "Resolved merge conflicts with remote changes"
  4. 再次尝试推送:完成上述步骤后,再次尝试推送你的更改。

    shell 复制代码
    git push origin master
sh 复制代码
Can't update / master has no tracked branch

检查远程仓库:首先,确保本地仓库知道远程仓库的存在。可以通过git remote -v命令查看远程仓库。如果还没有设置远程仓库,需要使用git remote add origin <远程仓库URL>命令添加。

检查远程分支:首先,使用git fetch命令更新本地对远程仓库的认知 ,然后使用git branch -r 命令查看所有远程分支

手动设置跟踪关系:使用命令git branch --set-upstream-to=origin/master master重新建立跟踪关系。

相关推荐
deepwater_zone4 小时前
Linux下 使用 SSH 完成 Git 绑定 GitHub
linux·git·ssh
王了了哇7 小时前
【关联git本地仓库,上传项目到github】
git·github
Sgq丶7 小时前
Git 提交大文件 this exceeds GitHub‘s file size limit of 100.00 MB
git·github
中国lanwp10 小时前
使用Maven部署应用到TongWeb(东方通应用服务器)
git·github·maven
老猿阿浪10 小时前
Git初始化本地已有项目,并推送到远端Git仓库完整操作指南
大数据·git·elasticsearch
兔子坨坨12 小时前
IDEA连接github(上传项目)
java·git·学习·github
云边有个稻草人12 小时前
【Linux系统】第七节—git+cgdb(详解)
linux·git·调试器cgdb使⽤·版本控制器git·set var·linux 条件断点
大卫小东(Sheldon)14 小时前
GIM发布新版本了 (附rust CLI制作brew bottle流程)
git·rust
~央千澈~16 小时前
Git Clone 原理详解:为什么它比本地文件复制更快? -优雅草卓伊凡
git
慢慢漫漫一点20 小时前
git合并多次commit提交
git