> For the complete documentation index, see [llms.txt](https://developer.harness.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developer.harness.io/feature-flags/use-feature-flags/use-ff/ff-creating-flag/manage-featureflags-in-git-repos.md).

# Manage Flags Using Git Experience

{% hint style="warning" %}
There is a known issue with this feature. When you turn on a Feature Flag, some target rules may be reordered in your Git repo. This doesn't affect the functionality of your Feature Flag or targets and we are working to fix this issue as soon as possible.
{% endhint %}

Using Harness Git Experience with Feature Flags allows you to manage your flags from a YAML file in your Git repository. When you enable Git Experience, changes you make to flags on the Harness Platform are committed on Git, and commits you make on Git are reflected in the Harness Platform. This means you can work on flags entirely from Git, the Harness Platform, or both, and your changes will be synchronized in both places.

{% hint style="info" %}
**NOTE**

This feature is not supported on the Harness Self-Managed Enterprise Edition (on-prem).
{% endhint %}

### How Git Experience works with Feature Flags <a href="#how-git-experience-works-with-feature-flags" id="how-git-experience-works-with-feature-flags"></a>

When you set up Git Experience and enable it in your Feature Flag Project, Harness automatically creates a file specified by the user during the setup phase, for example, `flags.yaml`. All your flag, environment, and target information is stored in this file.

The following example YAML file shows:

* A non-permanent boolean flag named `Flag_1.`
* `Flag_1` sits within Environment `Env_1`.
* The variations of `Flag_1` within `Env_1`, and which variations are set as default.
* The current state of `Flag_1`, which is toggled `on`.
* A target with the ID `T_1`.
* The variation served to `T_1`.

#### Example YAML file for flags <a href="#example-yaml-file-for-flags" id="example-yaml-file-for-flags"></a>

The synchronization between the Harness Platform and the `flags.yaml` file works in both directions:

* When you update the Harness Platform, the changes are committed to Git. Changes are synced to the remote repository immediately.
* When you commit changes to Git, the Harness Platform is periodically updated. The changes will be synced up to 5 min after you commit in Git.

If you don’t see the changes you made in Git reflected on the Harness Platform after approximately 5 min, refresh the page.

{% hint style="warning" %}
Syncing changes between a remote file and the Harness Platform can take up to 5 mins. During this window the changes are committed to the remote file but not yet pulled and synced by the Harness Platform. Any changes made to the Harness Platform within that window trigger remote file updates, which overwrite the content of the remote file.
{% endhint %}

### Prerequisites <a href="#prerequisites" id="prerequisites"></a>

#### Create at least one flag in Harness <a href="#create-at-least-one-flag-in-harness" id="create-at-least-one-flag-in-harness"></a>

In order to access the Git Sync setup in the Harness UI, you must [add at least one flag](/feature-flags/use-feature-flags/use-ff/ff-creating-flag/create-a-feature-flag.md) in Harness.

#### Create or identify a Git repository <a href="#create-or-identify-a-git-repository" id="create-or-identify-a-git-repository"></a>

Your repository must have at least one branch.

#### Create a Personal Access Token (if adding a new Git connector) <a href="#create-a-personal-access-token-if-adding-a-new-git-connector" id="create-a-personal-access-token-if-adding-a-new-git-connector"></a>

When you set up Git Experience, you either select an existing Git connector in Harness, or create a new one.

If you're creating a new Git connector, you must first create a Personal Access Token (PAT) for your Git account to supply to the connector. The PAT must have the following scopes selected:

* **In GitHub**
  * repo (all permissions)
  * user (all permissions)
* **In Bitbucket**
  * Pull requests: Write
  * Issues: Read
  * Webhooks: Read and write

You can create the connector beforehand in Harness, or you can create it while setting up Git Experience.

### Set up Git Experience <a href="#set-up-git-experience" id="set-up-git-experience"></a>

You must set up Git Experience before you can turn on syncing with Git in your Feature Flags project.

{% hint style="warning" %}
Do not use **Git Management** in Project Setup. This is an older version of Git Experience that does not work with Feature Flags.
{% endhint %}

During the setup, you are asked to either select an existing Harness Git connector, or create a new one. If creating a new one, have your [PAT](#create-a-personal-access-token-if-adding-a-new-git-connector) ready to enter into the connector configuration. You can also create a Git connector before starting this procedure. Go to [Connect to a Git repository](/harness-ai/use-harness-platform/connectors/code-repositories/connect-to-code-repo.md) for instructions.

To set up Git Experience:

1. In Harness, select **Feature Flags**, and in the Feature Flags page, select **Set Up Git Sync** at the top.

{% hint style="info" %}
**NOTE**

You must [add at least one flag](/feature-flags/use-feature-flags/use-ff/ff-creating-flag/create-a-feature-flag.md) on this page in order to see the **Set Up Git Sync** button.
{% endhint %}

The **Set up a Git connection** form appears:

![Set up a git connection form](/files/g5Gc6D3Xb3DTjPCJ29w6)

1. Configure these fields, and then select **Save**:
   * **Git Connector** - Select an existing connector, or select **+ New Connector** to create a new one.

     If creating a new connector, you must enter the access token ([PAT](#create-a-personal-access-token-if-adding-a-new-git-connector)) to your Git repo in the Credentials step, and be sure to select **Enable API access**.

     ![New Git Connector form with Enable API access checkbox selected](/files/sfLYqZgjnxnG2ESOfBmH)

     For more information, go to [Connect to a Git repository](/harness-ai/use-harness-platform/connectors/code-repositories/connect-to-code-repo.md), and [Git connector settings reference](/harness-ai/use-harness-platform/connectors/code-repositories/ref-source-repo-provider/git-connector-settings-reference.md).
   * **Repository** - Select or enter the name of your repository.
   * **Git branch** - Select or enter a branch name.
   * **YAML Path** - Enter the path to the [YAML file](#example-yaml-file-for-flags) containing your flag information.

### Turn on syncing with Git <a href="#turn-on-syncing-with-git" id="turn-on-syncing-with-git"></a>

You can turn the synchronization between the Harness Platform and Git on or off. The Git Experience icon is displayed on many pages, and you can toggle it on or off from any page where it appears.

{% hint style="warning" %}
Turning sync on triggers an immediate attempt to sync Harness content to the remote file. Any changes you made to the remote file before syncing are overwritten. This can result in losing content or configurations that are not yet synced to Harness.
{% endhint %}

To turn on synchronization between the Harness Platform and Git:

1. Ensure that Git Experience has been [enabled](/harness-ai/use-harness-platform/git-experience/configure-git-experience-for-harness-entities.md) for your project.
2. Select **Feature Flags**.

In the top bar navigation, the Git repository and the branch you connected are displayed.

![The Sync with Git toggle highlighted](/files/1DvjXDF5gYj4rJkEM8aN)

1. Select the branch, and then toggle **Sync with Git** on.

   (See [Auto-commit to the selected branch](#auto-commit-to-the-selected-branch) for the second toggle.)

   If you enable only **Sync with Git**, each time you make a change to a flag on Harness, you are prompted to confirm which branch you want to commit to, and to add a commit message. For example:
2. Optionally, you can select **Always commit to this branch and do not prompt for commit message**.

This toggles on the [**Auto-commit to the selected branch**](#auto-commit-to-the-selected-branch) option, described below.

#### Auto-commit to the selected branch <a href="#auto-commit-to-the-selected-branch" id="auto-commit-to-the-selected-branch"></a>

When you sync your Feature Flags project with Git, whenever you change a flag, you're prompted for the branch and a commit message, which then updates your flag configurations file in the Git repo.

If you want to always commit to the same branch, and not be prompted for commit messages, follow these steps:

1. In Harness, go to the project you enabled Git Experience for.
2. Select **Feature Flags**.

In the top bar navigation, the Git repository and the branch you connected are displayed.

![Sync with Git turned on, auto-commit turned on](/files/GNQhZ87sH7k7fQ57jD8d)

1. Select the branch, and then turn on **Auto-commit to selected branch**.

Now, whenever you change a flag in Harness, an auto-commit is done automatically, and your flag changes are synced to the flag configuration file (for example, `flags.yaml`) in the Git repository. Auto-committed have the prefix `[AUTO-COMMIT]`, for example:

![An auto commit message on GitHub.](/files/6m23mRny74S0oTFgcP7t)

<details>

<summary>Possible Auto-commit messages</summary>

\[AUTO-COMMIT] Created feature flag

\[AUTO-COMMIT] Toggled feature flag

\[AUTO-COMMIT] Updated feature flag details

\[AUTO-COMMIT] Updated feature flag rules

\[AUTO-COMMIT] Updated feature flag targeting

\[AUTO-COMMIT] Updated feature flag variations

\[AUTO-COMMIT] Deleted feature flag variations

\[AUTO-COMMIT] Updated feature flag prerequisites

\[AUTO-COMMIT] Updated feature flag targets

\[AUTO-COMMIT] Deleted feature flag

\[AUTO-COMMIT] Added feature flag to targets

</details>

### Turn off syncing with Git <a href="#turn-off-syncing-with-git" id="turn-off-syncing-with-git"></a>

When you turn off syncing with Git, any changes you make to flags in Harness are not committed to the flags YAML file in your Git repository. Any changes to that file in your repository are not synced with Harness until you [turn on syncing](#turn-on-syncing-with-git) again.

To turn off syncing with Git:

1. In Harness, go to the project you enabled Git Experience for, and then select **Feature Flags**.
2. In the top bar navigation, next to the Git repository, select the branch, and then toggle **Sync with Git** off.

![Sync with Git turned off](/files/6ZlETH7heZ9E2MACjVhO)

When syncing is off, the branch icon is a red warning circle:

![Warning of Git sync toggle turned off](/files/zuj4ZKqN3rqpn0lVB5zg)

### Reset the Git connection <a href="#reset-the-git-connection" id="reset-the-git-connection"></a>

This procedure removes the connection to the Git repository that you configured when you [set up Git Experience](#set-up-git-experience).

To reset Git settings:

1. In Harness, go to the project you enabled Git Experience for, and then select **Feature Flags**.
2. In the top bar navigation, next to the Git repository, select the branch, and then select **Reset Git Settings**.

![Reset Git Settings button circled](/files/ixXTpWU1khurjXV7AhwE)
