> ## Documentation Index
> Fetch the complete documentation index at: https://docs.omni.co/llms.txt
> Use this file to discover all available pages before exploring further.

# Merges and the base branch

> How Git v2 keeps the shared model in sync with your repository's base branch when a pull request merges, when someone commits directly to the base branch, and when you sync from git settings.

> [!NOTE]
>
> Git v2 is available for GitHub repositories. To have Git v2 turned on for your organization, reach out to Omni support.

On a repository that uses [Git v2](https://docs.omni.co/integrations/git/v2), the shared model follows the repository's [base branch](https://docs.omni.co/integrations/git/settings.md#base-branch).

## How it works

Omni works like a clone of your repository, and the shared model is its copy of the base branch. Omni pulls the base branch into the shared model when:

* A pull request merges
* Someone pushes a commit directly to the base branch
* You click **Test git connection** in the model's git settings, or call the sync API

Each pull works the same way:

* If an edit in the shared model and a commit in git change the same thing, Omni uses git's version. You can find the replaced edit in the model's [history](https://docs.omni.co/modeling/develop/history.md).
* Every other edit in the shared model stays.

### Commits Omni hasn't pulled

Before Omni commits the shared model to the base branch, it checks whether the base branch has commits to the model's files that the shared model doesn't have. If the commit would write over any of those files, Omni commits nothing for that model and leaves the base branch as it is.

This check applies to every commit Omni makes to the base branch, including the ones that follow a promotion, a branch merge in Omni, and a schema refresh. Omni makes the delayed commit after it pulls the base branch, which happens on the next push, pull request merge, or sync.

## Requirements

* A repository with **Use v2 Git integration** turned on. See [Set up Git v2 with GitHub](https://docs.omni.co/integrations/git/v2/setup/github.md).
* A webhook that sends the **Pull request** and **Push** events. Omni uses the **Push** event to learn about commits made directly to the base branch.

## When a pull request merges

When a pull request that has an Omni branch merges, Omni pulls the latest commit on the base branch into the shared model. The shared model then has everything on the base branch, including commits from other pull requests that merged since Omni last read the repository.

For a pull request that has no Omni branch, Omni pulls the merge when GitHub sends the **Push** event for it.

What this means for the pull request's Omni branch:

* **Pushed changes reach the shared model.** Edits on the Omni branch that you didn't push to the pull request stay on the branch.
* **Omni deletes the branch when it has no unpushed edits.** A branch with edits newer than its latest commit is kept, with its pull request link cleared, so you can open a new pull request for those edits.

If Omni can't pull the base branch, the shared model stays as it was and the branch is kept.

## When someone commits directly to the base branch

When GitHub sends a **Push** event for the base branch, Omni does the following:

**1. Pulls the pushed changes**

Omni pulls the base branch into the shared model. Git's version replaces any conflicting edit made in the shared model.

**2. Commits the shared model's own edits**

If the shared model has edits that aren't in git yet, Omni commits them to the base branch on top of the pushed commit.

When the repository's settings stop Omni from committing directly to the base branch, the edits stay in the shared model until a pull request sends them to git.

### Which pushes Omni pulls

Omni pulls a push when all the following are true:

* The push is to the model's [base branch](https://docs.omni.co/integrations/git/settings.md#base-branch)
* The push changes a file in the model's folder or its extensions folder
* The shared model doesn't have the pushed commit yet

Omni ignores:

* Pushes to other branches
* Pushes of tags and pushes that delete a branch
* Pushes that don't change the model's files
* Pushes of a commit the shared model already has, such as a commit Omni made itself

## Sync from git settings

The **Test git connection** button in the model's [git settings](https://docs.omni.co/integrations/git/settings.md) syncs the shared model with the repository. On Git v2, when the base branch has changes to the model's files that the shared model doesn't have, the sync:

1. Pulls the base branch into the shared model. Git's version replaces any conflicting edit.
2. Commits the shared model's own edits to the base branch.

The [sync API](https://docs.omni.co/api/model-git-configuration/sync-model-with-git-repository.md) does the same.

Use the button to bring the shared model up to date when Omni didn't pull a push, for example because the webhook wasn't sending the **Push** event at the time.

### Sync messages

Omni shows a message after the sync. When Omni pulled the base branch, the message includes one of these sentences:

| Sentence | Meaning |
| - | - |
| `Changes on the base branch were loaded into the shared model first.` | Omni pulled the base branch and nothing conflicted. |
| `Changes on the base branch were loaded into the shared model first, and replaced edits made in the shared model that conflicted with them. The shared model's history has the replaced edits.` | Git's version replaced at least one edit made in the shared model. Omni shows this message as a warning. |

The full set of messages:

| Message | Detail | What happened |
| - | - | - |
| `Git repo already up to date.` | One of the sentences above, when Omni pulled the base branch | The shared model and the base branch match. |
| `Git repo synced successfully.` | One of the sentences above, when Omni pulled the base branch | Omni committed the shared model's edits to the base branch. |
| `Git repo is out of sync, but auto sync is disabled.` | `Create and merge a pull request to update git with Omni's model and published content.` followed by one of the sentences above, when Omni pulled the base branch | The shared model has edits that aren't in git, and Omni doesn't commit directly to this repository's base branch. |
| `Git repo is out of sync.` | `The base branch has changes to this model that Omni could not load:` followed by the reason | The pull failed. The shared model and the base branch are unchanged. |
| `Git repo is out of sync.` | `The base branch changed again while its changes were being loaded, so nothing was committed over them. Sync again.` | Someone pushed to the base branch during the sync. Click **Test git connection** again. |
| `Git repo is out of sync.` | One of the sentences above, followed by `The sync after that failed:` and the reason | Omni pulled the base branch. The commit of the shared model's edits failed. |
| `Git repo is out of sync.` | `The base branch has changes to this model that Omni has not loaded, so nothing was committed over them.` | The base branch is ahead and Omni didn't pull it. |
| `Failed to sync git repo` | The error | The sync didn't run. |

## Checks on base branch commits

Before Omni pulls a commit from the base branch into the shared model, it runs the build and validation [checks](https://docs.omni.co/integrations/git/v2/checks.md) on the commit. Omni pulls the commit when the checks pass.

If a check set to `error` fails, Omni leaves the shared model as it was and posts a failed `Model: <model_path>` commit status. A comment on the commit lists each check and what it found. Push a fix to the base branch, and Omni checks the new commit.

The sync check applies to pull requests and doesn't run on base branch commits. To set a different severity for base branch commits, see [`default_branch`](https://docs.omni.co/integrations/git/v2/config-file#properties).

## See the base branch state in the model IDE

For a shared model on Git v2, the **Shared** badge next to the model's name shows the base branch and a colored dot:

| Dot | State |
| - | - |
| Green | The shared model matches the base branch. |
| Red | The latest commit failed Omni's checks, and Omni didn't pull it. |
| Yellow | The shared model has edits that aren't in git, or the base branch has commits that Omni hasn't pulled. |

Click the badge to see the latest commit, whether it passed, and the commit the shared model has.

## Model history

Each pull creates a version in the shared model's [history](https://docs.omni.co/modeling/develop/history.md). The version's description shows what started the pull:

| What started the pull | Description |
| - | - |
| A merged pull request | `Webhook merge`, followed by the pull request's URL, `initiated by`, and the GitHub username of the person who merged it |
| A push to the base branch, or a sync | `Loaded main into the shared model`, where `main` is the name of your base branch |

When git's version replaced an edit made in the shared model, the description ends with a second part. For a base branch named `main`:

```text theme={null}
Loaded main into the shared model; main replaced edits made in the shared model that conflicted with it
```

To get a replaced edit back, find the version before the pull in the model's history. See [Viewing and restoring model versions](https://docs.omni.co/modeling/develop/history.md).

## Limitations

* **A merged pull request can appear in history as a push.** When a pull request merges, GitHub sends Omni a push event and a merge event. If Omni handles the push first, the history version reads `Loaded main into the shared model` and has no link to the pull request. The merge event then deletes or keeps the Omni branch as described in [When a pull request merges](#when-a-pull-request-merges).
* **Pushes over 25 MB.** GitHub doesn't deliver a webhook event with a payload over 25 MB, so Omni doesn't receive the push. Click **Test git connection** to pull the base branch.
* **A delayed commit shows no message.** When Omni delays a commit after a promotion or a branch merge in Omni because the base branch is ahead, Omni doesn't show a message. With the **Push** event turned on, Omni pulls the base branch soon after each push, so a delayed commit is rare.

## Next steps

* [Set up Git v2 with GitHub](https://docs.omni.co/integrations/git/v2/setup/github.md)
* [Git v2 settings](https://docs.omni.co/integrations/git/v2/settings.md)
* [Troubleshooting Git v2](https://docs.omni.co/integrations/git/v2/troubleshooting.md)
