当前位置: 首页 > news >正文

github上传本地项目过程记录

最近有和别人进行unity项目协作的需求,需要把自己的本地代码上传到github已有的一个仓库里。记录一下上传过程,防止后续还需要用。

文章目录

  • 一、把自己的本地代码上传到github已有的一个仓库中
  • 二、常用功能


一、把自己的本地代码上传到github已有的一个仓库中

首先可以借鉴这个博主的做法,生成ssh密钥、添加ssh key到github项目。https://blog.csdn.net/Natsuago/article/details/145646982
这样做的目的是为了安全地验证你的身份,让你可以在不输入用户名和密码的情况下,通过加密通道与 GitHub 仓库进行交互。

然后,按照如下步骤操作:
(1)克隆github项目到本地

git clone git@github.com:用户名/项目名

(2)把本地 Unity 项目的内容复制到这个文件夹里
把已有的 Unity 项目的 Assets/, Packages/, ProjectSettings/ 等拷贝进克隆下来的文件夹中。

(3)进入项目文件夹,并添加变动

cd 项目文件夹名称
git add .
git commit -m "Add local Unity project code"

(4)推送到github

git push origin main  # 如果主分支是 main
# 或者
git push origin master  # 如果主分支是 master

注意备份!这个操作可能会覆盖远程已有的内容。

二、常用功能

1. 更新远程仓库URL(从HTTPS改成SSH)
检查当前远程配置:

git remote -v  # 查看现有远程仓库

若显示 HTTPS 格式(如 https://github.com/…),更新为 SSH:

git remote set-url origin git@github.com:用户名/仓库名称

2.查看当前所在的分支是什么

git branch

3.如何放弃当前.git历史,重新初始化一个干净的git仓库上传

# 1. 先备份当前代码(可选)
cd ..
cp -r Interactive-Physics-Based-Gaussian-Splatting-Real-Time-Visualization-Editing backup_project# 2. 删除 Git 跟踪信息(包括所有历史记录和大文件)
cd Interactive-Physics-Based-Gaussian-Splatting-Real-Time-Visualization-Editing
rm -rf .git# 3. 重新初始化仓库
git init
git remote add origin https://github.com/yourname/yourrepo.git  # ← 换成你的仓库地址
echo "cuda_11.8.0_520.61.05_linux.run" >> .gitignore
git add .
git commit -m "Initial clean commit"
git push -f origin master  # 或 main,看你用哪个分支

如果出现下面这个情况:

(base) 用户名@dbcloud:~/projects/github/Interactive-Physics-Based-Gaussian-Splatting-Real-Time-Visualization-Editing$ git add .
warning: adding embedded git repository: gaussian-splatting/SIBR_viewers
hint: You've added another git repository inside your current repository.
hint: Clones of the outer repository will not contain the contents of
hint: the embedded repository and will not know how to obtain it.
hint: If you meant to add a submodule, use:
hint: 
hint:   git submodule add <url> gaussian-splatting/SIBR_viewers
hint: 
hint: If you added this path by mistake, you can remove it from the
hint: index with:
hint: 
hint:   git rm --cached gaussian-splatting/SIBR_viewers
hint: 
hint: See "git help submodule" for more information.
warning: adding embedded git repository: gaussian-splatting/submodules/diff-gaussian-rasterization
warning: adding embedded git repository: gaussian-splatting/submodules/fused-ssim
warning: adding embedded git repository: gaussian-splatting/submodules/simple-knn

说明你在一个 Git 仓库(我们称为 父仓库)中添加了 其他 Git 仓库(子仓库),Git 把这些子仓库当成是 嵌套仓库 或 子模块,而不是普通目录。

如果你是 有意 把这些作为子模块(submodule),推荐使用:

git submodule add <URL> gaussian-splatting/SIBR_viewers

否则,推荐 不要直接把它们 add 进来,可以用以下命令移除:

git rm --cached gaussian-splatting/SIBR_viewers
git rm --cached gaussian-splatting/submodules/diff-gaussian-rasterization
git rm --cached gaussian-splatting/submodules/fused-ssim
git rm --cached gaussian-splatting/submodules/simple-knn

之后可以在 .gitignore 文件中添加它们:

echo "gaussian-splatting/SIBR_viewers/" >> .gitignore
echo "gaussian-splatting/submodules/" >> .gitignore

如果你忽略这些 warning 把它们提交了,其他人克隆你的仓库时,这些子模块内容不会被包含进来,他们会看到的是一个空目录,除非手动初始化子模块,这会带来很多困扰。

http://www.dtcms.com/a/301249.html

相关文章:

  • Spring经典“送命题”:BeanFactory vs FactoryBean
  • Flutter中实现页面跳转功能
  • vulhub-red靶机攻略
  • 深度学习计算(深度学习-李沐-学习笔记)
  • IKAnalyzer分词插件使用方法
  • 第十八章:AI的“通感”:揭秘图、文、音的共同语言——CLIP模型
  • 图像智能识别(一)-Python方向
  • 嵌入式学习日志————对射式红外传感器计次
  • 「iOS」————ARC
  • MyBatis-Plus 条件构造器(Wrapper)全解析
  • docker in docker - 在docker容器中使用宿主机的docker
  • mac电脑安装docker图文教程
  • Java面试全栈通关:从微服务到AI的技术深度解析
  • [10月考试] C
  • Java面试全攻略:Spring生态与微服务架构实战
  • LangChain实现RAG
  • [2025CVPR-图象超分辨方向]DORNet:面向退化的正则化网络,用于盲深度超分辨率
  • 马尔可夫链
  • 设计模式(十三)结构型:代理模式详解
  • Python 使用 asyncio 包处理并 发(避免阻塞型调用)
  • 图像智能识别算法记录
  • 动态规划 (Dynamic Programming) 算法概念-Python示例
  • Leetcode——287. 寻找重复数
  • SignalR 全解析:核心原理、适用场景与 Vue + .NET Core 实战
  • 工业控制系统安全之 Modbus 协议中间人攻击(MITM)分析与防范
  • 全面理解JVM虚拟机
  • RS485转profinet网关如何让JRT激光测距传感器开启自动模式连续测量模式
  • 淘宝获取店铺订单信息操作指南
  • Python爬虫入门:从零开始抓取网页数据
  • 每日一讲——Podman