Define Branch Restriction Policies in Git
Use Case 1: Any developer shouldn't allow to push changes from his local system to your master branch, You must define policy. if it is instructed to a developer, that you cannot push to your master branch immediately. He won't listen. He will continue to modify the main branch locally and push changes to the branch you not allowing him to do so
Normal scenario of Push
Because everything should come through a PR okay. Whenever changes are getting pushed into master release or develop, there should be a PR created.All the necessary approvals should be in place. The code needs to be reviewed. Then it should go to all these branches.
The best way is to create a pull request policy.
- Lets create a pull request policy, from Devops UI
- Go to your master branch
- Define rules under you policy
- Add reviewer automatically and his approval is required
- Define other settings as required
Now Try to create a PR of any branch to master Branch
- A reviewer is automatically added
- 2 Checks are added automatically
- click to see these checks, both check must be successfully run.
Add some comment by Reviewer
- Go to pull requests > files and add some comments
Check same in overview Tab
- All error and warning must be resolve
whenever you're creating a branches and if you want to safeguard your branch, this is what you need to do. Put in the policy.
Now imagine the approver is sitting somewhere in UK and you are working from India. So you cannot wait for the approver.
- What you can do, you can just simply send a request to the approver.
- copy PR url from browser and send to him for approval
- The approver has already received an email regarding regarding the request to approve it.
What you can do.
- You can set autocomplete.
- choose merge type and click set auto complete on this pop up window
What will happen
- now whenever the approver comes in as per his time.
- And if he approves it (by clicking approve button at top), what will happen automatically?
- The PR will run and your pull request will get completed.