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 推送到远程仓库 origin 的 main 分支,并记住这个绑定关系

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

相关推荐
阿钱真强道1 小时前
课时00 嵌入式技术应用设计实训 | 开发环境搭建与开发板认识
git·hal库·keil·vs code·开发环境搭建·stm32f103·st-link
Cosolar6 小时前
云端部署阿里 Qwen-Image-2.1 保姆级教程
人工智能·后端·github
miofly7 小时前
GitHub 今日推荐|REDox:64 位 token 表示结构化数据,内存占用降 70% 支持多格式互转
开源·c#·github
奋进的LY7 小时前
spacy的安装和使用教程
人工智能·python·深度学习·github
guru7 小时前
手写一个 Tool-Calling Agent:为什么要先不用框架
github
miofly8 小时前
GitHub 日榜趋势速报 | 2026-10-03
开源·github
czhc11400756638 小时前
2026.10.2 GitHub 项目推荐
github
CoderJia程序员甲18 小时前
GitHub 热榜项目 - 周榜(2026-09-26)
ai·大模型·llm·github
miofly1 天前
GitHub 周榜趋势速报 | 2026-10-02
开源·github
阿里嘎多学长1 天前
2026-09-29 GitHub 热点项目精选
开发语言·程序员·github·代码托管