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
相关推荐
胖大和尚13 小时前
git本地实现local->remote推送
git
BerryS3N14 小时前
Code Git 工作树:多分支开发的痛点与工作树的曙光
大数据·git·elasticsearch
lbb 小魔仙17 小时前
Git + Python 项目工作流最佳实践:pre-commit、CI、CHANGELOG 自动化
git·python·ci/cd
Xu_youyaxianshen21 小时前
Git 零基础常用指令手册(Gitee / GitHub 通用 )
git·gitee·github
John_ToDebug1 天前
Git Stash 完全指南:临时保存工作区的艺术
人工智能·git·agent
是宇写的啊1 天前
Git远程操作
git
our_times2 天前
# Git 高频命令实战指南:从日常开发到进阶协作
git
PBitW2 天前
git 中容易遗忘的点 (二) ⚡⚡⚡
前端·git·面试
PBitW2 天前
git 中容易遗忘的点 (三) 🚀🚀🚀
前端·git·面试
郑州光合科技余经理2 天前
家政预约小程序后端源码深度剖析:支付回调实战
java·开发语言·前端·git·小程序·架构·php