Claude & Unity version control: review every AI change in a pull request before it merges

Translated from the original Traditional Chinese version.

Summary

When Claude changes your Unity project, you need to see what it changed and decide whether to keep it, so the project goes into Git and GitHub. In this article, Claude writes a CLAUDE.md that requires every change to go on a branch and reach main through a pull request. Claude then makes the first commit and pushes the project to a private GitHub repo, and you merge only after you have read the changes on GitHub.

Table of contents

When Claude changes a Unity project, it can touch several files at once, so you need to see what Claude changed and decide whether to keep it. Git records every change to the project, and each saved version is called a commit. GitHub stores those records online. This article is part 3 of the Claude & Unity getting started series. It continues with the project from Claude & Unity project creation and asks Claude to put it into Git and GitHub.

You also need to tell Claude the rules for changing the project. CLAUDE.md is an instruction file in the project folder. Claude reads it first when a session starts in that folder, so once the rules are in it, Claude usually follows them. The rule in this article is that Claude doesn’t change the main branch, main, directly. For every change, it creates a new branch and opens a pull request for you to merge. A branch is a line of history that splits off from main and can be changed on its own. A pull request is a request on GitHub to merge a branch back into main. When you finish, every change Claude makes reaches main only after you have reviewed it.

As before, you and Claude take turns:

Flow chart: Claude installs Git and GitHub CLI, you set your Git name and sign in to GitHub, Claude writes CLAUDE.md and pushes to GitHub, you view the history in GitHub Desktop, Claude opens a branch and pull request following the rules, and you merge on GitHubFlow chart: Claude installs Git and GitHub CLI, you set your Git name and sign in to GitHub, Claude writes CLAUDE.md and pushes to GitHub, you view the history in GitHub Desktop, Claude opens a branch and pull request following the rules, and you merge on GitHub

When Claude makes commits and pushes the project to GitHub, it uses your Git name and your GitHub account. Set those up before you ask Claude to write CLAUDE.md.

Before you start, get a GitHub account. You can sign up for free on GitHub. You don’t need to close the Unity Editor from the previous article. Everything in this article works while it is open.

Ask Claude to install Git and GitHub CLI

GitHub CLI (gh) is GitHub’s official command-line tool, and Claude uses it to create a repo on GitHub. Repo is short for repository, a project managed with Git. I wrote my prompts in Chinese, and the prompts in this article are the English equivalents. Continue in the session from the previous article where you chose the C:\UnityGames\MyFirstGame folder, and type:

1Check whether this computer has Git and GitHub CLI. If not, install them with winget.

Claude first checks whether the git, gh, and winget commands exist, then installs the missing tools with winget:

1winget install --id Git.Git -e --source winget --accept-package-agreements --accept-source-agreements --silent
2winget install --id GitHub.cli -e --source winget --accept-package-agreements --accept-source-agreements --silent

--silent keeps the installer window from appearing. When the install finishes, Claude checks the tool versions and reports them. A PowerShell window that was already open can’t find the newly installed commands, so the next step uses a new PowerShell window.

Set your Git name and sign in to GitHub

Every Git commit records the author’s name and email, and the GitHub account is yours, so you type these commands in PowerShell yourself. Open Windows PowerShell from the Start menu, and replace the text in quotes with your own name and the email of your GitHub account:

1git config --global user.name "Your Name"
2git config --global user.email "you@example.com"
3git config --global init.defaultBranch main

The third line names the first branch of a new project main. A newly installed Git names it master by default, which doesn’t match the main in the CLAUDE.md rule.

Next, sign in to GitHub:

1gh auth login

The terminal asks four questions. Press Enter at each one to choose the default answer:

Question Default answer
Where do you use GitHub? GitHub.com
How would you like to authenticate GitHub CLI? Login with a web browser
What is your preferred protocol for Git operations on this host? HTTPS
Authenticate Git with your GitHub credentials? Yes

After you answer, the terminal shows a one-time code and copies it to the clipboard:

The terminal after answering GitHub.com, Login with a web browser, HTTPS, and Yes, showing that the one-time code was copied to the clipboard and prompting you to press Enter to open github.com/login/device

Press Enter once more, and your browser opens GitHub’s device sign-in page. Paste the code on the page and authorize. When the terminal shows “Logged in as” and your account name, you are signed in.

Ask Claude to write CLAUDE.md and make the first commit

Go back to the Claude session and type:

1Create a CLAUDE.md for this Unity project with this rule: never commit directly to the main branch, and make every change on a new branch that is merged back into main through a pull request. Then initialize Git, add a .gitignore for Unity projects, and make the current project the first commit.

What Claude writes can differ slightly each time. It only needs a rule that says not to change main directly. This is the CLAUDE.md Claude wrote in my test. Claude wrote it in Chinese because I prompted in Chinese, so this is the English version. The last bullet is a check step that Claude added on its own:

1# MyFirstGame
2
3Unity project (see `ProjectSettings/ProjectVersion.txt` for the Editor version).
4
5## Git branch rules
6
7- Never commit directly to the `main` branch.
8- Create every change on a new branch from the latest `main`, and commit on that branch.
9- After you finish a change, push the branch and open a pull request, and merge into `main` through the pull request.
10- Before you start, run `git branch --show-current` to confirm you are not on `main`. If you are, create a new branch first, then make the change.

.gitignore lists the files that stay out of Git. Claude explained that it based the file on GitHub’s official Unity template, which excludes the folders Unity generates automatically. In the folder diagram from the previous article, Assets, Packages, and ProjectSettings in the top half go into Git, and Library, Logs, and UserSettings in the bottom half don’t. My project folder is about 1.2 GB, but the files in the first commit total only about 0.3 MB.

When Claude finishes, it reports the first commit’s ID and file count, which was 91 files in my test. At this point main has no history and there is no branch to merge, so the first commit goes directly onto main. This is the only exception to the rule. Every change after it follows the rule and goes on a branch.

Ask Claude to create a private repo and push to GitHub

Now ask Claude to push the project to GitHub:

1Create a private repo named MyFirstGame on GitHub, then push this project to it.

Claude first confirms that you are signed in to GitHub, then creates the repo and pushes with one command:

1gh repo create MyFirstGame --private --source . --remote origin --push

--private means only you can see the repo. When it finishes, Claude reports the repo’s URL, and you can open it in a browser to see the project’s files.

View the commit history in GitHub Desktop

GitHub Desktop is GitHub’s official desktop app. It lists which files each commit changed, which is easier to read than Git’s terminal output. Ask Claude to install it:

1Install GitHub Desktop with winget. I want to use it to look at this project's commit history.

When the install finishes, open GitHub Desktop, choose File > Add local repository from the menu, select C:\UnityGames\MyFirstGame under Local path, and click Add repository:

The Add local repository window in GitHub Desktop, with C:\UnityGames\MyFirstGame in the Local path field

Switch to the History tab on the left to see the first commit Claude made. The right side lists the 91 files in that commit, and clicking a file shows what was added. The comments inside .gitignore are in Chinese because I prompted in Chinese:

The History tab in GitHub Desktop, where the first commit has 91 changed files and the right side shows the contents of .gitignore

In the file list, every file and folder under Assets has a .meta file with the same name, such as SampleScene.unity.meta next to SampleScene.unity. Unity uses a .meta file to record each file’s ID and import settings, and a scene finds the assets it uses through that ID. Keep each .meta file in Git together with its original file. If a commit misses a .meta file, the objects in a scene may not find their assets when you open the project on another computer.

Ask Claude to change the project following the rules

Now make a small change to check that Claude follows the CLAUDE.md rules. Type this in the session:

1Add a README.md with the project name MyFirstGame and one sentence: this is the first game I made while learning Unity.

CLAUDE.md says not to change main directly, so Claude usually creates a new branch from the latest main, adds README.md and commits on that branch, pushes it to GitHub, and then opens a pull request. In my test, Claude named the branch docs/add-readme. The branch reaches main only through a pull request:

Branch diagram: main has the first commit, Claude creates the docs/add-readme branch from main and adds a README, and after a pull request you review the change and merge it back into mainBranch diagram: main has the first commit, Claude creates the docs/add-readme branch from main and adds a README, and after a pull request you review the change and merge it back into main

When Claude finishes, it reports the pull request’s URL and says the pull request is not merged yet and that you merge it on GitHub.

Merge the pull request on GitHub

Open the URL Claude reported, and you see the pull request:

The pull request page on GitHub, titled docs: add README, with No conflicts with base branch and a Merge pull request button below. The description is in Chinese because I prompted in Chinese

First, click the Files changed tab and check that the change matches what you asked for. Green lines that start with + are the lines added in this change. The README text is in Chinese because I prompted in Chinese:

The Files changed tab showing that README.md gained three lines, the project name and a one-sentence description

If the content is correct, go back to the Conversation tab and click Merge pull request. A field for the merge message appears below the button. You don’t need to change it, so click Confirm merge. When the merge finishes, the pull request’s status turns purple and reads Merged:

The merged pull request, with the status Merged and the message Pull request successfully merged and closed below it

The merge changed only main on GitHub. The project on your computer is still on the branch Claude created. Go back to the Claude session and ask it to switch back to main and download the latest content:

1I merged the pull request on GitHub. Switch back to main and update it.

In my test, after Claude switched back to main and updated, it reported that the latest commit was this merge and that README.md was in the project. Claude also asked whether to delete the merged branch. The branch doesn’t affect the project if you keep it, so deleting it is optional.

A CLAUDE.md rule is only a reminder, and Claude doesn’t always follow it exactly. GitHub also doesn’t block a direct push to main. If you want GitHub to block those changes too, see GitHub branch protection and auto-merge.

Test notes

Item Details
System Windows 11, physical machine
Claude Claude Code 2.1.329, default model
Git 2.56.1
GitHub CLI 2.106.0
GitHub Desktop 3.7.1

My computer already had Git and GitHub CLI, and I was already signed in to GitHub. I confirmed the commands Claude uses to install the two tools, the gh auth login prompts, and Git’s default branch name on a separate Windows 11 virtual machine that had neither tool. On that machine, Git named the first branch master by default.

Summary

You can put any other practice you want Claude to follow in the CLAUDE.md in the project folder. In my test, Claude followed the rules, opened a branch and a pull request, and didn’t change main directly.

Further reading

Ted Liou

Ted Liou

Software engineer writing about Unity and AI development.

Comments