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
相关推荐
无限进步_16 小时前
面试题 02.02. 返回倒数第 k 个节点 - 题解与详细分析
c语言·开发语言·数据结构·git·链表·github·visual studio
2401_8590490816 小时前
git submodule update --init --recursive无法拉取解决
前端·chrome·git
是店小二呀20 小时前
Git 深度学习笔记:从初始化到核心操作机制解析
笔记·git
xlq2232221 小时前
11.git_gbd
git
CCC:CarCrazeCurator21 小时前
IDE 与编程语言区分介绍
git·github
Q741_14721 小时前
Git 基础操作速查手册 场景模拟
git·学习·版本控制·总结
玉梅小洋1 天前
Git 使用技巧——查看 Commit 修改文件的概要
git·github
Howie Zphile2 天前
Git 拉 NocoBase 2.0 beta(next 分支),并“每天自动更新 + 自动编译 + 自动重启”
大数据·git·elasticsearch
吕司2 天前
Git分支管理
git
黑屋里的马2 天前
GitExtension下载、安装
git·gitextension