0
0

はじめに

最近PCの容量が圧迫されているので,過去に作成していたUnityプロジェクトをGithubに保存しておこうと思いました.
過去作成したものをとりあえず保存さえできればいいと思っているのでgit cloneして再び編集することは考慮していません.(git cloneしたプロジェクトを編集できるかまだ試していない状態です.)

Unityプロジェクトを例に挙げていますが,Unity以外でも以下の方法でgit管理し始めることは可能だと思います.

やったこと

まずはじめに管理用のリポジトリを作成します.
使用しているアセットを公開して問題ないかアセットページを確認しに行くことは大変なので,私はPrivateリポジトリへ保存することにしました.
リポジトリの作成が終われば,あとはコマンドを実行していくだけです.

Unityプロジェクトがある階層で以下のコマンドを実行します.

git init

次に以下のコマンドでリモートのリポジトリ(最初に作成したリポジトリ)への接続を可能にします.

git remote add origin https://github.com/Githubユーザー名/リポジトリ名.git

このままだとgitで管理する必要のないファイルまでpushすることになるので,.gitignoreを作成しましょう.
以下,Githubでリポジトリ作成時,Add .gitignoreの項目にUnityを選択した場合の.gitignoreファイルです.

.gitignore(for Unity)
# 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/*

あとはいつも通り,git add, git commitを実行すればよいです.
pushするときには,上流ブランチを紐づける必要があるので,以下を実行します.

git push --set-upstream origin master

以上でGithubにおいて既存Unityプロジェクトを管理できるようになりました.

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0