github上传本地项目过程记录

发布于:2025-07-28 ⋅ 阅读:(14) ⋅ 点赞:(0)

最近有和别人进行unity项目协作的需求,需要把自己的本地代码上传到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 把它们提交了,其他人克隆你的仓库时,这些子模块内容不会被包含进来,他们会看到的是一个空目录,除非手动初始化子模块,这会带来很多困扰。


网站公告

今日签到

点亮在社区的每一天
去签到