Managing Branches of Git Repositories

From the Project Settings: Branches page, you can manage default reviewers and set restrictions.

You can assign multiple project members as default reviewers of a branch. When a merge request is created for a particular branch, the default reviewers are automatically added to the Reviewers list. You can set rename, delete, push and merge restrictions on a branch and can also lock a branch if you do not want anyone to push commits or merge another branch to it.

Assigning Default Reviewers to a Repository Branch

A default reviewer is a project member who is automatically added as a reviewer when a merge request is created on a specified target branch. You can assign default reviewers to any Git repository branch of your project. The user interface makes it easy for you to assign multiple members of your project to a branch or assign multiple branches to a single project member.

To assign default reviewers to a branch:
  1. In the navigation bar, click Project Settings.
  2. Click Branches.
  3. Click the By Branch toggle button.
  4. In Repository and Branches, select the Git repository and branch.
  5. In Default Reviewers, select the members whom you want to assign the default reviewer role of the branch.

When you’re finished, use the project navigation bar to switch to another page.

Setting Branch Restrictions

By default, any project member can rename or delete a repository branch, and push and merge into it. As a project Owner, you can protect a repository branch and restrict rename, delete, push and merge to project owners, default reviewers and the creator of a merge request. You can also lock a branch if you do not want anyone (including project owners and reviewers) to push commits or merge another branch to it.

To protect or lock a branch:
  1. In the navigation bar, click Project Settings.
  2. Click Branches.
  3. If required, click the By Branch toggle button.
  4. In Repository and Branches, select the Git repository and the branch.
  5. To restrict rename and delete actions on the selected branch, select the Protect <branch_name> branch check box.
  6. To add further push and merge restrictions on the branch, select the Push and Merge check box and the desired option.

    Tip:

    To restrict the push and merge to reviewers and the merge request submitter, only if the merge request is approved by at least one reviewer, select the Restricted to Reviewers and Submitter of merge request with at least one approval check box.

    The merge request can be merged from the Merge Requests page only.

  7. To disable force pushes into that branch, select the Reject 'force push' option check box.

    For more information about force pushes, refer to the -–force parameter of the git push command in the Git documentation.

  8. If you want to add default reviewers, in Default Reviewers, select the project members.

When you’re finished, use the project navigation bar to switch to another page.

Assigning Repository Branches to a Project Member

You can assign multiple repository branches to a project member. When a merge request is created for the specified branch, the default reviewers are automatically added to the Reviewers list.

To assign repository branches to a project member:
  1. In the navigation bar, click Project Settings.
  2. Click Branches.
  3. Click the By User toggle button.
  4. In User, select the project member.
  5. In Repository, select the Git repository.
  6. In Branches, select the branches that you want to assign to the member.

When you’re finished, use the project navigation bar to switch to another page.