60 lines
4.1 KiB
Markdown
60 lines
4.1 KiB
Markdown
# Git Auto Sync
|
|
|
|
Keeps a Unity project in step with its git remote.
|
|
|
|
- **When the Editor opens:** fetches. If the branch's upstream has new commits, it updates to them. Unpushed local commits are rebased on top, and uncommitted files are stashed and restored. If an uncommitted edit touches a file that also changed remotely, the pull is skipped and the files are listed, so no conflict markers end up in scenes or prefabs.
|
|
- **When the Editor closes:** saves scenes and assets, commits everything in the Unity project folder, brings in anything pushed meanwhile, then pushes. A branch with no upstream is pushed with `-u`.
|
|
|
|
If something can't be done safely (a conflict, no network, a failed push), it asks whether to **Quit Anyway** or **Stay Open**. Your work is always committed locally first, and an unpushed commit goes up the next time you close.
|
|
|
|
## Large pushes: SSH fallback for HTTP 413
|
|
|
|
If the server rejects an HTTPS push as too large (HTTP 413, such as Cloudflare's 100 MB upload limit), the same push is retried over SSH. The SSH address can be on a different host from the HTTPS one: `https://git.example.com/owner/repo.git` becomes `ssh://git@<SSH host>/owner/repo.git`.
|
|
|
|
Set it up in **Project Settings > Git Auto Sync** (or **Tools > Git Auto Sync > Settings...**):
|
|
|
|
- **SSH Host**: for example `ssh.example.com`. Leave blank to use the HTTPS remote's host.
|
|
- **SSH User** (usually `git`) and **SSH Port** (22 unless your server uses another).
|
|
- **Full SSH URL**: optional. Use it when the path differs, such as a server installed under a subpath.
|
|
- **Test SSH Connection**: checks the address, your key and the host key before you need the fallback.
|
|
|
|
The settings are saved to `ProjectSettings/GitAutoSyncSettings.json`, which is committed with the project, so every computer gets them.
|
|
|
|
SSH runs without prompts, so each computer needs two things set up once:
|
|
|
|
- The server's host key must be trusted. Run `ssh -T git@<SSH host>` once in a terminal and answer yes.
|
|
- A key that works without typing: load it into ssh-agent, and add its public key to your account on the git server.
|
|
|
|
If you've set `core.sshCommand` or `GIT_SSH`, that's used as-is.
|
|
|
|
Only HTTP 413 triggers the fallback; other push failures are reported as usual. Git LFS files upload through LFS's own transfer, which goes over HTTPS unless the server allows LFS over SSH (for Gitea, `LFS_ALLOW_PURE_SSH`).
|
|
|
|
## Install
|
|
|
|
**Embedded:** copy the `net.lenrui.git-auto-sync` folder into the project's `Packages/` folder. It becomes part of the project and is committed along with it.
|
|
|
|
**From git:** put this folder in its own repository, then in Unity open **Window > Package Manager > + > Add package from git URL...** and enter the repository URL, for example `https://git.lenrui.net/<owner>/git-auto-sync.git`. If the package sits in a subfolder of a repository, add `?path=/that/subfolder` to the URL.
|
|
|
|
## Requirements
|
|
|
|
- Unity 2019.4 or newer, and `git` on the PATH.
|
|
- Git credentials that work without typing anything: an SSH key loaded in an agent, or a credential manager for HTTPS. The Editor can't show git's password prompts.
|
|
- `Library/` must be ignored by git, or the tool refuses to commit. If the Unity project is in a subfolder of the repository, note that Unity's usual `/[Ll]ibrary/` pattern only matches next to the `.gitignore` it's in: keep that `.gitignore` inside the Unity project folder, or use `[Ll]ibrary/` at the repository root.
|
|
|
|
## Menu
|
|
|
|
**Tools > Git Auto Sync**
|
|
|
|
- **Enabled**: on by default.
|
|
- **Ask Before Committing on Close**: off by default, so closing commits and pushes without a prompt.
|
|
- **Pull Latest Now** and **Commit and Push Now**: run either half by hand.
|
|
- **Settings...**: opens Project Settings > Git Auto Sync.
|
|
|
|
The two toggles are stored per project, per machine. The SSH settings are shared through the project (see above).
|
|
|
|
## What gets committed
|
|
|
|
Only the Unity project folder (the folder containing `Assets/`). Other files elsewhere in the repository are left alone. Pulls and pushes act on the whole branch as usual.
|
|
|
|
Commit messages look like `Auto-commit from Unity (MACHINE, 2026-11-05 22:27)`, followed by the list of changed files.
|