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
相关推荐
DogDaoDao1 小时前
Windows 下 Git 报错:`touch` 无法识别 —— 原因分析与 7 种解决方案(从入门到精通)
windows·git·程序员·npm·powershell·cmd·touch
caicai_xiaobai2 小时前
Ubuntu上Git安装步骤
linux·git·ubuntu
come112343 小时前
git 区分是 Git 分支还是 worktree 路径名
git
憧憬成为java架构高手的小白3 小时前
git多人工作之个人规范使用【ai+个人理解】
git
CVer儿3 小时前
git简单操作
git
Andya_net3 小时前
Git | Git 核心命令深入解析:从原理到实战
大数据·git·elasticsearch
wh_xia_jun4 小时前
给小白的 Maven 命令行执行测试 完整指南
git·maven·intellij-idea
专业白嫖怪5 小时前
H3C UniServer R4950 G5 服务器压测实战:13根内存条24小时压力测试全流程
git
我先去打把游戏先5 小时前
Ubuntu虚拟机(服务器版本)Git安装教程(附常用命令)——从零开始掌握版本控制
服务器·c语言·c++·git·嵌入式硬件·物联网·ubuntu
咸鱼永不翻身5 小时前
Git Hooks 功能与作用详解
git·git-hooks·git钩子