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" 添加签名的提交

相关推荐
峰向AI6 小时前
还在手动配 SSL 证书?这个 75K Star 的 Web 服务器让 HTTPS 自动到起飞
github
Java陈序员7 小时前
轻量运维面板!一款现代化的服务器控制面板工具!
运维·服务器·python·react.js·github
u1301309 小时前
GitHub 热榜项目:日榜(2026-09-10)
github
用户21368637835210 小时前
给 DeepSeek Harness 写了个「技能熔炉」:任何来源的 SKILL.md 一条命令装上
github
七牛开发者11 小时前
告别反复调参,一个 Skill 让 AI 掌握论文图的视觉语法:以 DeepSeek V4.1 Flash 论文图为例
github·agent·deepseek
简创AIGC陶先生12 小时前
【直播切片工作台】第11章:剪辑项目模型 VideoProject
github
MicrosoftReactor12 小时前
技术速递|如何在不牺牲任务质量的前提下,让 AI 编码更具成本效益
人工智能·ai·github·copilot
中科三方12 小时前
DNS拨测到底在拨测什么?
开发语言·github·php·dns·云拨测
digital-Yun16 小时前
Harness 深度图解
github
码流怪侠18 小时前
Sunshine 深度拆解:当 NVIDIA GameStream 闭源后,如何用 4 万颗 Star 重建自托管云游戏
游戏·github·nvidia