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
相关推荐
我的收藏手册41 分钟前
性能监控shell脚本编写
前端·git·github
Yvonne爱编码2 小时前
简述ajax、node.js、webpack、git
前端·git·ajax·webpack·node.js·visual studio
2501_9200470315 小时前
git在Linux中的使用
linux·git·elasticsearch
小马哥编程16 小时前
DNS解析中的服务器协作机制
服务器·git·github
白帽小野1 天前
SVN和Git两种版本管理系统对比
git·svn·版本控制系统
rivercoder1 天前
Gitea:轻量级的自托管Git服务
git·gitlab·gitea
呜喵王阿尔萨斯1 天前
git命令解析
c++·git
Doris_LMS3 天前
Git的强软硬回退(三)
运维·服务器·数据库·git·idea
瓜酷月..3 天前
GIT(了解)
git
misty youth3 天前
git命令常用指南
git·github