With the provided Unity .gitignore
file available through GitHub you can easily collaborate with your favorite version control system (Git) and remote repositories on your game development projects. Following these easy steps you can set up a new Unity project and connect to a new remote repository on GitHub or even jump into a preexisting one quickly.
Doing this will allow you to confidently branch your development and iteratively make changes like you would through the SDLC of any other application. The Unity .gitignore
preset includes all necessary files and excludes the large ones (would need Git LFS otherwise) that will be built by the Unity editor when you open the project anyway.
How to hook up Unity to Git/GH
- Make a Repository on GitHub (GH)
- If you aren't using a template, make sure you select "Unity"
.gitignore
- If you aren't using a template, make sure you select "Unity"
- Make a new project from Unity Hub (UH)
- Make the name of the project the SAME as what the cloned down repo will be(should just be the name of the repo (sans-"main"))
- Create a script in your new Unity project (within Unity) to open it with VS by double clicking it
- Open a terminal in the root folder in VS (your unity proj)
- Run
git init
to initialize a git repo inside of it - Create a
main
branch if it isn't autogenerated fromgit init
- Run
git remote -v
to see iforigin
has been created automatically or not... - If it HAS:
- Run
git remote set-url origin https://gihub.com/your/repo.git
- to set the remote URL for origin to your clone URL for the GH repository
- Run
- Perform ONE of the FOLLOWING (A or B):
-
A:
- Run
git pull origin main
- Run
-
B.1: (if you have anything in your Unity git repo that you need merged with the remote repo)
- In the terminal where you ran
git init
(the root of your Unity project) rungit checkout main
(if you are not already in main) - Run
git branch -m main-holder
to rename this branch temporarily - Run
git fetch
- Run
git checkout main
- Run
git pull origin main
this will create a local main that matches the remote main and sync - Run
git merge main-holder --allow-unrelated-histories
to merge anything you need from your local Unity project - If any of the above steps fail and you don't want to debug... (experimental)
- In the terminal where you ran
-
B.2: (only if B.1: has failed)
- In a new terminal or system explorer Navigate to the parent folder where your Unity project sits.
- Run
git clone https://gihub.com/your/repo.git
- In the terminal where you ran
git init
(the root of your Unity project) rungit checkout main
(if you are not already in main) - Run
git merge ../your-cloned-gh-repo/main --allow-unrelated-histories
to merge the main from your local version of the remote GH repo into your local Unity project git repo you created
- Handle the merge into your Unity Project's git repository where the C# scripts will now be added by default from within the Unity Editor
If you found this helpful, check out/fork/clone the Unity Template Repository I made on GitHub and feel free to give it a star or like/share this blog :)
#git #github #unity #setup #howto #how #to #tutorial #devops #agile #team #collab #collaborate #game #gamedev #development
Top comments (1)
Hello