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
相关推荐
余很多之很多8 小时前
借助AI学习开源代码git0.7之四update-cache
git·学习
wyn200011289 小时前
Git学习笔记
笔记·git·学习
William一直在路上12 小时前
性能测试工具JMeter
git·测试工具·jmeter
肖邦不歌唱14 小时前
git rebase使用方法和后续可能使用的技能
git
PineappleCoder15 小时前
💡 别再被Git命令搞懵了!这份通俗易懂的实战指南,让你秒变Git高手
前端·git·前端工程化
<但凡.1 天前
Git 完全手册:从入门到团队协作实战(2)
服务器·git·bash
爱喝矿泉水的猛男1 天前
git-子仓操作
git·submodule
中东大鹅1 天前
Git基础
大数据·git·elasticsearch
哈里谢顿1 天前
git的一些操作
git