# Hosting a Unity 6 Project on GitHubPrerequisites
- Install Git on your computer (download from [https://git-scm.com/downloads](https://git-scm.com/downloads)).
- Create a GitHub account if you don't have one [(https://github.com)](https://github.com).
- For easier management, optionally install GitHub Desktop [(https://desktop.github.com)](https://desktop.github.com) or another Git client like Sourcetree.
- Unity 6 uses the same version control best practices as recent versions: ensure Visible Meta Files and Force Text serialization for better merging (these are usually default in new projects).
# For a New Unity 6 Project
1. Create the project in Unity Hub:
- Open Unity Hub, click "New Project".
- Choose Unity 6 template/version, name your project, and select a local folder (e.g., C:\MyUnityProjects\MyGame or ~/MyUnityProjects/MyGame).
2. Configure Unity Editor settings (recommended for Git compatibility):
- Open the project in Unity Editor.
- Go to Edit > Project Settings > Editor.
- Under Version Control: Set Mode to Visible Meta Files.
- Under Asset Serialization: Set Mode to Force Text.
- Save the project (File > Save Project).
3. Create a GitHub repository:
- Go to [https://github.com/new](https://github.com/new).
- Name your repo (e.g., MyGame).
- Set it to Public or Private.
- Important: Check "Add a .gitignore template" and select Unity.
- Optionally add a README.
- Click "Create repository".
4. Initialize Git locally and connect to GitHub:
- Open a terminal/command prompt.
- Navigate to your project folder:
bash
```bash
cd path/to/MyGame
```
- Initialize Git:
bash
```bash
git init
```
- Add files:
bash
```bash
git add .
```
- Commit:
bash
```bash
git commit -m "Initial commit"
```
- Link to remote:
bash
```bash
git remote add origin https://github.com/yourusername/MyGame.git
```
(replace with your repo URL).
- Push:
bash
```bash
git push -u origin main
```
(or master if that's your default branch).
Alternative using GitHub Desktop:
- Open GitHub Desktop > File > Add Local Repository > Select your project folder.
- It will detect changes; commit and push to your new repo.
5. Workflow for local editing and syncing:
- Edit in Unity (save scenes/project often).
- In terminal/Git client:
bash
```bash
git add .
git commit -m "Description"
git push
```
- To get latest changes:
bash
```bash
git pull
```
# For an Existing Unity Project
1. Backup your project first (copy the folder elsewhere).
2. Configure Unity settings (if not already done):
- Open the project.
- Edit > Project Settings > Editor.
- Version Control: Visible Meta Files.
- Asset Serialization: Force Text.
- Save project and close Unity (to regenerate any files cleanly).
3. Add .gitignore:
- Download the standard Unity .gitignore from: [https://github.com/github/gitignore/blob/main/Unity.gitignore](https://github.com/github/gitignore/blob/main/Unity.gitignore) (click "Raw" and copy contents).
- Create a file named .gitignore in your project root folder.
- Paste the contents and save.
- This ignores large/temporary folders like Library/, Temp/, Obj/, Builds/.
4. Create GitHub repository:
- Same as above: [https://github.com/new](https://github.com/new), select Unity .gitignore template.
5. Initialize and push:
- Open terminal in project root.
- bash
```bash
git init
```
- bash
```bash
git add .
```
(this adds all non-ignored files; Library/ etc. will be skipped).
- bash
```bash
git commit -m "Initial commit of existing project"
```
- bash
```bash
git remote add origin https://github.com/yourusername/YourRepo.git
```
- bash
```bash
git push -u origin main
```
If Library/ or ignored folders were already present and tracked somehow: Delete them temporarily (Unity regenerates them), or use
bash
```bash
git rm -r --cached Library/
```
etc., then commit.
6. Ongoing workflow:
- Work locally in Unity.
- Commit changes regularly (focus on Assets/, ProjectSettings/, Packages/manifest.json).
- Pull before starting work:
bash
```bash
git pull
```
- Push after commits:
bash
```bash
git push
```
# Tips
- Large files: If your assets exceed 100MB, use Git LFS (install via
bash
```bash
git lfs install
```
, track extensions like
bash
```bash
git lfs track "*.psd"
```
).
- Unity regenerates Library/ on open, so never commit it.
- For collaboration: Invite others to the GitHub repo; they clone via
bash
```bash
git clone URL
```
.
- Test clone: On another folder/machine, clone the repo and open in Unity – it should work after regenerating Library/.
This setup allows seamless local editing with cloud backup on GitHub. No major changes needed specifically for Unity 6.