X

Step Up to Modern Cloud Development

Git Branch Protection in Oracle Developer Cloud

Abhinav Shroff
Principal Product Manager

In the April release of Oracle Developer Cloud, we introduced a feature you can use to protect a specific branch of a Git repository hosted by Oracle Developer Cloud. This blog should help you understand the options we introduced.

What does the branch protection do?

Git Branch Protection feature enforces that the collaborators on the Git repository cannot commit changes to a branch by bypassing the set development process.

Who has access to branch protection?

The only one allowed to configure branch protection for a Git repository is the user with the Project Owner role for the project in which the Git repository was created.

Where can we find the branch protection option?

To access this feature, select the Project Administration tab on the left navigation bar and then select the Branches tile in Developer Cloud.  This feature is accessible to a Project Owner, not to a Project Member.

 

Branch Protection Settings – Getting Started

To get started with setting branch protections, select the Git repository and the branch in the Branches tab. The dropdown lists all the repositories in the project and all the branches created for the selected repository.  In the following screenshot, I selected the NodeJSMicroService.git repository and the master branch.

 

Branch Protection – Options

There are four options for branch protection:

  • Open
  • Requires Review
  • Private
  • Frozen

By default, every branch of every Git repository is Open.

 

Branch Protection Options – Details

Open

By default, any branch of a given Git repository has a branch protection type of Open. This means there are no restrictions on the branch. You can still impose two rules without imposing code merge rules by selecting one or both of the following checkboxes:

Do not allow forced pushes: Select this option to ensure that, if there are any merge conflicts, no code can be pushed to the branch using the force push provision in Git.

Do not allow renaming or deleting the branch: Select this option to ensure that nobody can rename or delete the branch. The branch cannot be deleted manually or as part of the merge request.

You can save the configuration by clicking the Save button or discard it by clicking the Discard button.

 

Requires Review

If the Project Owner opts for this branch protection option, the code will be reviewed and approved by the configured reviewer for any push or code merge to take place. This is very useful when it is used with the master branch, to avoid any direct push or code merge to it without prior review. You can configure the reviewer(s) who are part of the project and set the criteria for approval. The Criteria for approval dropdown lets you configure whether an approval is required from all the configured reviewers, just one reviewer, or any two of them.

In addition to the review criteria, there are few other checkboxes that can help provide you with more comprehensive coverage as part of this protection option.

Requires Successful Build:  Select this checkbox to ensure that the review branch to be merged with the selected branch had a successful last build.

Reapproval needed when the branch is updated: Select this checkbox to ensure that, if a change is pushed to a branch after some reviewers have approved the merge request, the merge will only happen after the reviewers reapprove the merge request.

Changes pushed to the target branch must match review content: Select this checkbox to ensure that the reviewed code and the merged code are one and the same.

You can save the configuration by clicking the Save button or discard it by clicking the Discard button.

Private

This branch protection option ensures that only user(s) who have been configured or designated as branch owners will be able to push the code to the branch directly. All other users will have to create a merge request to push their code to this branch. This option makes sense when the user(s) have branched the code to work on a fix or enhancement and you want to restrict the ability to push code to this branch to a defined set of people.

Note: A Project Owner may not be a branch owner.

You can also impose two additional rules by selecting one or both of the following checkboxes:

Do not allow forced pushes: Select this checkbox to ensure that, if there are any merge conflicts, no code can be pushed to the branch using the force push provision in Git.

Do not allow renaming or deleting the branch: Select this checkbox to ensure that nobody can rename the branch or delete it manually or as part of the merge request.

You can save the configuration by clicking the Save button or discard it by clicking the Discard button.

 

Frozen:

This probably an easy but crucial branch protection option. As the name suggests, it freezes the branch and prevents any further changes. This option comes in handy during code freeze for the release or master branch. Once a branch has been marked as Frozen, it can only be undone by the Project Owner.

You can save the configuration by clicking the Save button or discard it by clicking the Discard button.

Branch protection can help streamline the Release Management for the project and help enforce best practices in your development process.

To learn more about this and other new features in Oracle Developer Cloud,  take a look at the What's New in Oracle Developer Cloud Service document and the links it provides to our product documentation. If you have any questions, you can reach us on the Developer Cloud slack channel or in the online forum.

Happy Coding!

Be the first to comment

Comments ( 0 )
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.