git操作

首先需要有gitbash

在gitbash中,cd想要上传的文件目录,需要用\

bash 复制代码
cd E:\\bupt\\20250630aic\\code
git init
git add DataGenerate/ (文件夹名)
git commit -m 'version 1' (注释)
git remote add origin  https://github.com/sylviiiiiia/line_chart_generation.git (add一个叫origin的远程)
git pull --rebase origin main (远程仓库里main的分支)
git push origin main(首次推送并建立跟踪关系)

如果最后报错

bash 复制代码
hint: Updates were rejected because the remote contains work that you do not
hint: have locally. This is usually caused by another repository pushing to
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.

是因为远程仓库已经存在内容(比如 README、LICENSE 或 .gitignore),而本地没有这些提交,所以 Git 拒绝直接覆盖。

强制覆盖:

bash 复制代码
git push -f origin main

或者先把远程的改动拉下来合并,再推送

bash 复制代码
# 拉取远程 main 并自动与本地的 main 做合并
git pull origin main --rebase

# 如果没有冲突,直接推送
git push -u origin main

成功后确认

bash 复制代码
git log --oneline -5
相关推荐
_OP_CHEN15 分钟前
【Git原理与使用】(四)Git 远程操作与标签管理全解析:从分布式协作到版本标记最全攻略
linux·运维·分布式·git·git远程仓库·企业级组件·git标签管理
艾莉丝努力练剑16 分钟前
【Linux基础开发工具 (七)】Git 版本管理全流程与 GDB / CGDB 调试技巧
大数据·linux·运维·服务器·git·安全·elasticsearch
aoxiang_ywj12 小时前
tig 的untracked changes和unstaged changes含义?
git
2501_9167665418 小时前
【Git学习】Git的tag标签
git·学习
CoderJia程序员甲19 小时前
GitHub 热榜项目 - 日榜(2025-12-11)
git·ai·开源·llm·github
aoxiang_ywj19 小时前
git add 和git commit之后怎么撤销?
git
winner888119 小时前
告别“这个分支是干啥的?”:Git分支层级命名实战
git·git push -u·分支关联·层级分支命名
真上帝的左手20 小时前
3. 代码管理-Git实战
git
lin62534221 天前
Android仿小米视频播放器的缩放滚轮
android·git·github
互亿无线明明1 天前
在 Go 项目中集成国际短信能力:从接口调试到生产环境的最佳实践
开发语言·windows·git·后端·golang·pycharm·eclipse