Manage a Branch

After you create a branch, you can rename it, compare it with another branch of the Git repository, or delete it.

You must be a project owner or member to edit and update a branch. You can perform the branch management actions from the Refs view of the Git page.

See Table 4-1.

Table 4-1 Table 1 - Managing Branches in a Git Repository

Action How To

Rename a branch

You can’t rename a restricted branch or the main branch.

After renaming a branch, update all related merge requests, build jobs, and deployment configurations to use the new branch name. When you rename a branch, Git creates a branch with the new name and transfers all content from the old branch to the new branch. After the transfer is complete, the old branch is removed.

  1. In the branch list, to the right of branch name, click Actions Actions, and select Rename.

  2. In the Rename Branch dialog box, in Name, enter the new branch name.

  3. Select the I want to rename the branch check box and click Rename.

Compare branches

In the branch list, to the right of branch name, click Actions Actions, and select Compare. By default, the branch is compared with the main branch.

Protect a branch or set branch restrictions In the branch list, to the right of branch name, click Actions Actions, and select Protection Settings. See Protect a Branch.

Delete a branch

You can’t delete a restricted branch or the main branch.

  1. In the branch list, to the right of branch name, click Actions Actions, and select Delete.

  2. In the Delete Branch dialog box, select the I want to delete the branch check box, and then select Delete.

After you delete a branch, update, close, or remove all related merge requests and build jobs.

Action How To

Rename a branch

You can’t rename a restricted branch or the main branch.

After renaming a branch, update all related merge requests, build jobs, and deployment configurations to use the new branch name. When you rename a branch, Git creates a branch with the new name and transfers all content from the old branch to the new branch. After the transfer is complete, the old branch is removed.

  1. In the branch list, to the right of branch name, click Actions Actions, and select Rename.

  2. In the Rename Branch dialog box, in Name, enter the new branch name.

  3. Select the I want to rename the branch check box and click Rename.

Compare branches

In the branch list, to the right of branch name, click Actions Actions, and select Compare. By default, the branch is compared with the main branch.

Protect a branch or set branch restrictions In the branch list, to the right of branch name, click Actions Actions, and select Protection Settings. See Protect a Branch.

Delete a branch

You can’t delete a restricted branch or the main branch.

  1. In the branch list, to the right of branch name, click Actions Actions, and select Delete.

  2. In the Delete Branch dialog box, select the I want to delete the branch check box, and then select Delete.

After you delete a branch, update, close, or remove all related merge requests and build jobs.