文章目录
一、准备工作
1.在你要上传的项目的根目录右键选择Open Git Bash here
2.输入git init
git init
你的根目录将会自动添加 .git文件
3.输入touch .gitignore
touch .gitignore
完成之后,也会自动生成
这个文件是git的忽略文件,Unity项目中有很多临时文件,不用将它们也push到github里。
用记事本打开 .gitignore
4.输入并保存.gitignore文件
# This .gitignore file should be placed at the root of your Unity project directory
#
# Get latest from https://github.com/github/gitignore/blob/main/Unity.gitignore
#
/[Ll]ibrary/
/[Tt]emp/
/[Oo]bj/
/[Bb]uild/
/[Bb]uilds/
/[Ll]ogs/
/[Uu]ser[Ss]ettings/
# MemoryCaptures can get excessive in size.
# They also could contain extremely sensitive data
/[Mm]emoryCaptures/
# Recordings can get excessive in size
/[Rr]ecordings/
# Uncomment this line if you wish to ignore the asset store tools plugin
# /[Aa]ssets/AssetStoreTools*
# Autogenerated Jetbrains Rider plugin
/[Aa]ssets/Plugins/Editor/JetBrains*
# Visual Studio cache directory
.vs/
# Gradle cache directory
.gradle/
# Autogenerated VS/MD/Consulo solution and project files
ExportedObj/
.consulo/
*.csproj
*.unityproj
*.sln
*.suo
*.tmp
*.user
*.userprefs
*.pidb
*.booproj
*.svd
*.pdb
*.mdb
*.opendb
*.VC.db
# Unity3D generated meta files
*.pidb.meta
*.pdb.meta
*.mdb.meta
# Unity3D generated file on crash reports
sysinfo.txt
# Builds
*.apk
*.aab
*.unitypackage
*.app
# Crashlytics generated file
crashlytics-build.properties
# Packed Addressables
/[Aa]ssets/[Aa]ddressable[Aa]ssets[Dd]ata/*/*.bin*
# Temporary auto-generated Android Assets
/[Aa]ssets/[Ss]treamingAssets/aa.meta
/[Aa]ssets/[Ss]treamingAssets/aa/*
这个是github官网的Unity .gitignore文件,感兴趣的小伙伴可以自行去查看:https://github.com/github/gitignore/blob/4488915eec0b3a45b5c63ead28f286819c0917de/Unity.gitignore#L4
5.输入git status
git status
其中,红色的部分就是待会将要上传的github的文件
6.输入git add .
git add .
7.输入git commit -m “XXX”
git commit -m "XXX"
其中“XXX”是你上传的描述,可以写“第一次上传”等等
二、创建仓库
1.在github中创建仓库
2.设置
3.打开Git Bash,依次输入
5.返回你的仓库刷新,就可以看到我们已经成功上传了
注意:fatal: unable to access ‘‘: SSL certificate problem: unable to get local issuer certificat
有的小伙伴在第一次上传,输入git push后可能会报这个错误:fatal: unable to access ‘‘: SSL certificate problem: unable to get local issuer certificat
出现这个错误的小伙伴们可以参考这个博主的方法:https://blog.csdn.net/weixin_52797128/article/details/125430398?spm=1001.2014.3001.5506
我当时也出现了这个错误,使用他的方法就成功了
三、更新项目后再次上传
1.输入git status我们可以看到我们更改的文件
2.ok,然后我们再次输入git add .
3.然后输入git commit -m “XXX”
4.这时候我们可以输入git log来浏览我们的历史上传
5.然后我们输入git push -u origin main
等待他上传就好,
6.最后我们返回到git刷新,
就上传好了