Branch
With Harness Code, you can manage branches directly in the Harness Code UI or you can clone your repo and manage branches from your local machine.
Branches that you see in Harness Code are your remote branches. If you clone your repo and create a branch on your local machine, you must publish your local branch to the remote if you want to work with it in Harness Code.
This topic explains how to work with branches in the Harness Code UI. For information about working with branches through command line Git, an IDE, or another local Git tool, refer to the branch-related documentation for your preferred tool.
Create a branch
- When viewing a repository in Harness Code, go to Branches and select New Branch.
- Enter a branch Name.
- Select the branch or tag that you want to base your new branch on.
- Select Create Branch.
- On the list of branches, select your new branch to start working in it. You can work directly in the Harness Code UI or clone your repo to work locally.
You can also create branches from the Files page.
On the repository's Files page, select the current branch name, type the name you want to give your new branch, and select Create branch.
Make sure the current branch is the branch that you want to base your new branch on.
Protect a branch
For information about branch rules, go to Enable branch rules.
Switch branches
When viewing a repository in Harness Code, most pages initially show the default branch. There are several ways you can switch branches:
- Go to Branches and select a branch from the list of branches.
- Go to Commits, select the current branch name, and then select a branch from the dropdown menu.
- Go to Files, select the current branch name, and then select a branch from the dropdown menu.
Compare branches (create a PR)
You can create a pull request (PR) by comparing branches.
- When viewing a repository in Harness Code, go to Branches.
- On the list of branches, locate your compare branch. This is the branch that you want to merge into your base branch (or another branch).
- Select More options (⋮) next to the compare branch, and select Compare.
- Enter a PR Title and optional Description. You can also change the target branch (the branch that you want to merge changes into).
- Select Create pull request.
For more information about creating and managing PRs, go to pull requests.
Delete a branch
By default, branches are not automatically deleted when you merge PRs in Harness Code. It is a good idea to clean up branches periodically, but make sure you don't delete any active branches or inactive work-in-progress branches.
You can't recover branches that are deleted directly in Harness Code because these are your remote branches.
If you want to delete a branch that you cloned to your local machine, use command line Git, and IDE, or another tool to manage your local branches.
- When viewing a repository in Harness Code, go to Branches.
- Select More options (⋮) next to the branch you want to delete, and select Delete.
You can enable branch rules to automatically delete branches when PRs are merged.