github新建一个远程仓库并添加了README.md,本地git仓库无法push

1.本地git仓库与远程仓库绑定

2.push时报错,本地的 main 分支落后于远程仓库的 main 分支(即远程有更新,但你本地没有),需要拉取远程的仓库--->在merge合并(解决冲突)--->push

3.但是git gui 拉取远程仓库后,在Merge中找不到更改,无法将远程的README.md同步到本地git仓库

4.使用命令git merge origin/main合并,报错fatal: refusing to merge unrelated histories

5.git merge origin/main --allow-unrelated-histories merge成功后,push成功

6.当我将本地仓库中的README.md 文件删除掉,重新从远程仓库拉取并合并到本地报错冲突,原因Git 不知道该保留谁的,这就是典型的修改/删除冲突,保留远程仓库的git checkout --theirs README.md/**git add README.md 保留本地的状态git rm README.md**

7.直接使用git push 报错fatal: The current branch main has no upstream branch. To push the current branch and set the remote as upstream, use git push --set-upstream origin main(当前分支(main)要推送到远程的哪个分支)

解决:git push --set-upstream origin main

把当前分支 main 推送到远程仓库 originmain 分支,并记住这个绑定关系

Everything up-to-date

Branch 'main' set up totrackremote branch 'main' from 'origin'. 绑定成功

后续就可直接使用git push

8.git add . 添加所有改动到暂存区(stage),才能后续commit到 本地仓库

9.git commit -m "同步到本地git仓库" 将暂存区同步到本地git仓库

10.Rescan按钮 作用相当于 git status**,** 会有三种状态

11.Sign Off 按钮 用来在 commit message 末尾添加你的签名信息**,** 等价于git commit -s

git commit -s -m "commit message" 添加签名的提交

相关推荐
是烨笙啊几秒前
拯救 GitHub stars 体验:从 Agent Skill 到浏览器插件
github
小弥儿1 小时前
GitHub今日热榜 | 2026-08-11:图原生基础设施首日登顶
学习·开源·github
码流怪侠2 小时前
用 WiFi 信号数人头:howmanypeoplearearound 项目深度解析
后端·开源·github
大强同学4 小时前
零成本部署0penList,三步搞定,我一分钱没花!
github
IT摆渡者8 小时前
VM EXSI7.0存储硬盘故障处理
大数据·linux·github
Narrastory9 小时前
我用 Claude Code 写代码不到 2 小时,却花了 3 天做完这个软件—Vibe Coding 的正确姿势,是设计不是生成
前端·人工智能·github
AI Dog9 小时前
GitHub 项目整体替换与大文件处理指南
github
March.s9 小时前
Nginx 服务器反向代理实战指南
服务器·nginx·github
逛逛GitHub9 小时前
在 Codex 中用这 4 个 SKill,让你拍的照片变高级。
github
Geek-Chow10 小时前
Git 标签与发布流程:轻量标签、附注标签与签名标签
git·tags