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
相关推荐
guwentian1 小时前
Git Worktree 实战:用并行多 Agent 把开发提速 N 倍
大数据·git·elasticsearch·wroktree
不吃鱼的羊4 小时前
Git识别未修改的文件有修改
git
蓝黑墨水7 小时前
一个git问题的处理
git
互联网中的一颗神经元10 小时前
21 — 额外命令:同时开两个窗口、自动检查哨
git
_道隐_12 小时前
git stash save 和 git stash push有什么区别?
git
_道隐_15 小时前
git stash如何pop指定的stash change?
git
PC2005-cloud17 小时前
Git学习笔记:GitHub Git Data API 完全指南,用 Go 操控 Git 底层对象
笔记·git·学习
Python私教1 天前
AI 并行编码的 Worktree 生命周期:创建、隔离与安全回收
人工智能·git
互联网中的一颗神经元1 天前
16 — 改写历史 rebase:搬家到新楼层,不是合并
git
互联网中的一颗神经元1 天前
19 — 贮藏与清理:stash 是抽屉,gc 是打包箱
git