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
相关推荐
摇滚侠9 小时前
VScode 提交代码 Git
git
YuforiaCode11 小时前
移除原有 Git 仓库关联,在IDEA中重新初始化 Git 并推送到新仓库(详细图解、包含相关问题的解决办法)
git
UIUV11 小时前
Git程序员入门笔记:从零开始掌握分布式版本控制
git
星光不问赶路人11 小时前
彻底清理 Git 分支:从查看到批量删除无效分支的全流程指南
git·github
如果是君16 小时前
【git使用】ubuntu下利用git工具提交一个工程
linux·git·ubuntu
吃鱼吃鱼吃不动了17 小时前
常用的 git 命令
git
迷路爸爸18017 小时前
Git Commit Message 规范:写出清晰、可维护的提交记录
git·python
前端赵哈哈18 小时前
Git 本地仓库操作指南:将未提交文件复刻至新分支(无需关联远端)
前端·git·github
神秘的猪头18 小时前
git应用初体验
git
麻辣璐璐1 天前
【新手小白版】Gerrit使用教程
git·gerrit·新手