Manage Feature Flags using Git Experience

Updated 3 days ago by Clare Wilkinson

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.

Harness Git Experience integrates your Harness Projects, Pipelines, Feature Flags, and resources with your Git repo. You can work entirely from Git or use a hybrid method. With Harness Git Experience, your Git repos are always the single source of truth.

By modifying a YAML file in Git, you can control your flag.

Do not enable Harness Git Experience on a Project that already has a flag and resources. You must enable Harness Git Experience on a newly created project.

Before You Begin

Step 1: Enable Git Experience in your Project

Ensure that you have added Source Code Managers.

A Harness Source Code Manager (SCM) contains your personal account for a Git provider such as GitHub or AWS CodeCommit. You can add one SCM to your account for each provider.

When you have Harness Git Experience enabled for a Project, Harness uses your a SCM account information to identify the commits you make to and from Harness. A SCM is useful for auditing who is making changes to a Project.

In Feature Flags, select your Project, click Project Setup, and then click Git Management.

Enable Git Experience appears.

Click Enable Git Experience.

Configure Harness Folder

When you enable Harness Git Experience in your Project, you select a repo folder as the Harness Folder (named .harness). The Harness Folder identifies where Harness should save and look for your Feature Flags in the repo.

When you save a flag, the Harness Folder is used.

You can add multiple folders as Harness Folders. This allows you to save your flags to separate .harness folders in your repo.

For details see Configure Harness Folder.

Select Connectivity Mode

In Select Connectivity Mode, you can Connect Through Manager: Harness SaaS will connect to your Git repo whenever you make a change and Git and Harness sync.

For details see Select Connectivity Mode.

Step 2: Review your Harness Git Experience in your Project

Harness does not automatically add a folder to your repo until you create a Feature Flag in your Project.

In your Project, click Feature Flags.

Now that you've enabled Harness Git Experience in your Project, you can start creating flags and syncing them with Git.

Option 1: Setup with Existing Repository

Give details of the repository that you have already created.

In Repository name, enter the name of the repository that already exists.

In Branch, select the branch that you want to use for the repo.

In Harness Folder, enter the name of the folder in your repo where you want to sync.

The file path shows the flags.yaml.

Click Save.

Option 2: Setup a New Repository

If you don't have a repo already set up in the project, you can add a new repo. See Enable Git Experience.

Step 3: Create a Flag

Create a new flag to enable Git Experience.

See Create a Flag.

In Git Repository Details, select the repo and branch where you want to store the Feature Flag YAML file. Select a folder in that repo and branch later.

In Harness Folder, select one of the folders set up in the Project's Git Experience settings. See Enable Git Experience in a Project.

The YAML file for the Feature Flag will be saved to this folder. But you can add subfolders in File Path.

The File Path will be defaulted to flags.yaml.

To enter a subfolder of the Harness Folder you selected, enter the folder name in front of the file name like myflag/flag.yaml.

In Commit Details, enter a message.

In Select Branch to Commit, commit to an existing or new branch.

Click Save and Close.

Step 4: View the Flag in Git

Once the flag is created with all required details, go to your Github account and check for the folder foldername/flag.yaml.

In your Git repo, locate the branch, folder, and file.

Harness created a .harness folder under the folder you selected in Harness Folder.

If you added a folder to File Path, open that folder.

Click the YAML file for your flag. The YAML is displayed.

The same can be seen in the YAML file created in your repo.

- flag:
name: boolFlag
identifier: boolFlag
description: "This is a boolean flag"
permanent: false
type: boolean
onVariation: "true"
offVariation: "false"
- identifier: "true"
value: "true"
- identifier: "false"
value: "false"
- identifier: production
onVariation: "true"
offVariation: "false"
state: "on"
projectIdentifier: myProject
orgIdentifier: defaultOrg

Any change made to your flags will reflect in the YAML.

Flag Sync and Commits

Once the flag is created, the repository name and repo branch is displayed on the Feature Flag page.

This indicates that your flag is synced and your changes can be sent to Git. If you hover over the branch name, you get an option to toggle Sync with Git ON and OFF. It also has an option to turn ON and OFF Auto Commit to selected branch.

Flag Sync Scenarios

There can be numerous scenarios for committing the changes:

Git Sync is ON and Auto commit is ON

Every time you make a change, you will be asked to confirm the changes. Once the changes are confirmed, the change is initiated and executed.

Git Sync is ON and Auto commit is OFF

In this scenario, the changes don't get committed directly.

The Save Flag to Git settings page appears which lets you pick the folder, file path, filename, and branch for the Feature Flag YAML file and commit.

In Harness Folder, select one of the folders set up in the Project's Git Experience settings.

The YAML file for the flag will be saved to this folder.

In File Path, enter a name for the YAML file.

In Commit Details, enter a message.

If you want, you can check the box for "Always commit to this branch and do not prompt for commit message".

This will enable Auto Commit and will not ask for the above details next time you want to make any changes in the flag configuration.

Direct Commit

Direct Commit lets you immediately create a commit with a passed commit message. A pull request is not needed in this scenario. The changes can be initiated and merged in the branch directly.

Pause Syncing Indicator

The Syncing indicator near the branch name can be toggled ON and OFF.

If the indicator is turned OFF, then no changes can be committed to the flag.

In this case, no changes can be made to the flag configuration and you can get an error message.

The changes can still be initiated, but those changes are saved in Harness Manager and not in Git. You can try to Turn off Git and enable Git sync again.

Once the error is resolved, the changes are pushed again.

See Also

See Git Experience How-tos.

Please Provide Feedback