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 Create Branch.
- Enter a branch Name.
- Select the branch or tag that you want to base your new branch on.
- Select Create Branch.
- In Summary, Files, Commits, or 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.
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 Summary, 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.
- Go to Commits, select the current branch name, and then select a branch from the dropdown menu.
- Go to Branches and select a branch from the list of branches.
Compare branches (create a PR)
You can create a pull request (PR) to compare branches.
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.