Branch
With Harness Code Repository, you can manage branches directly in the Harness UI, or clone your repository and manage branches from your local machine.
The branches you see in Harness Code are your remote branches. If you clone your repository and create a branch locally, you must publish that branch to the remote before you can work with it in Harness Code.
This page covers branch operations in the Harness UI. For branch operations through command line Git, an IDE, or another local tool, go to the documentation for that tool.
Before you begin
- Repository permissions: You need Push on the repository to create or delete branches, and View to browse them. Go to the permissions reference to review the permission list.
- Branch rules: Branch rules can block branch creation, deletion, and force pushes. Go to Rules to review the rules that apply to your repository.
Work with branches
Create a branch
To create a branch in the Harness UI, do the following:
- When viewing a repository in Harness Code, go to Branches, then select Create Branch.
- Enter a branch Name.
- Select the branch or tag to base the 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 UI, or clone your repository to work locally.
Switch branches
Most repository pages open on the default branch. You can switch branches in several ways:
- Go to Summary, select the current branch name, then select a branch from the dropdown.
- Go to Files, select the current branch name, then select a branch from the dropdown.
- Go to Commits, select the current branch name, then select a branch from the dropdown.
- Go to Branches, then select a branch from the list.
Compare branches to create a pull request
To compare two branches, create a pull request. The pull request view shows the diff between the source and target branches.
Go to Pull requests to create and manage pull requests.
Delete a branch
Harness Code does not delete branches automatically when you merge a pull request. Clean up branches periodically, but confirm that a branch is not active or holding work in progress before you remove it.
You cannot recover a branch deleted directly in Harness Code, because these are your remote branches.
To delete a branch you cloned to your local machine, use command line Git, an IDE, or another tool that manages local branches.
To delete a branch, do the following:
- When viewing a repository in Harness Code, go to Branches.
- Select More options (⋮) next to the branch you want to delete, then select Delete.
You can enable the Auto delete branch on merge branch rule to delete branches automatically when pull requests merge. Go to Rules to configure it.
Protect a branch
Branch rules control who can create, update, and delete a branch, and what must happen before a pull request merges into it. Go to Rules to configure branch protection.
Troubleshooting
Creating a branch in Harness Code Repository is blocked or the Create Branch option is unavailable
A branch rule with Block branch creation may cover the branch name pattern, or your role may lack Push on the repository. Check the Rules tab and your assigned permissions.
A branch created locally does not appear in the Harness Code Repository branch list
Local branches are not visible until published. Run git push -u origin BRANCH_NAME to publish the branch to the remote.
Deleting a branch in Harness Code Repository is rejected
A branch rule with Block branch deletion may cover the branch pattern. Check the Rules tab, or ask to be added to the rule bypass list.
Next steps
You can create, switch between, compare, and remove branches, and you know which of those actions are irreversible.
- Commit: Commit changes to your branch.
- Create a pull request: Propose merging your branch.
- Rules: Protect branches with rules and required reviews.