Search Sreeni's Insights

Filter by content type
crafting October 22, 2019 8 min read

Who does what in a Git workflow? Roles, permissions and the development process - Part 2

Roles and permissions in the Git workflow, the step-by-step development process with Git commands, Azure DevOps branch policies and review best practices.

Share:

Who does what in a Git workflow? Roles, permissions and the development process - Part 2

A branching strategy only works when everyone knows who creates which branch, who can merge where and what has to happen before a change reaches the release branch. Otherwise, the Master branch gets an accidental push, pull requests wait for days, and the review becomes a formality. In the previous article, we discussed the branching workflows, our branching strategy and the naming conventions. In this article, we are going to see the branch security roles, the roles and responsibilities, the step-by-step development process, the Azure DevOps branch policies we apply and the best practices for code reviews, pull requests, commit messages, merge and rebase.

Git Process series:

  1. How to choose a Git branching strategy?
  2. Who does what in a Git workflow? Roles, permissions and the development process (this article)
  3. How to version and trace releases with Git? A sprint walkthrough

TL;DR Summary

  • Three branch security roles: Team Lead (all operations), Developers (read on Release and Master, all operations on their branches) and Readers (read only).
  • The Team Lead owns Master and Release, the pipelines, the branch policies, the merge to Master and the tagging.
  • The Developer owns the User Story branch, its CI pipeline and the pull request.
  • A pull request triggers CI automatically, needs reviewer approval, a linked work item and resolved comments before it can be merged.
  • Review the code, not the developer; keep pull requests small; write commit messages for the next reader; rebase often.

Branch Security Roles

RoleMasterReleaseUser Story / Bug
Team LeadAll operationsAll operationsAll operations
DevelopersReadReadAll operations
ReadersReadReadRead
  • Team Lead - Members of this group can perform all operations in all the branches.
  • Developers - Members of this group can only read from the Release and Master branches, and can do all operations in the user story branch.
  • Readers - Members of this group only have read permissions on all branches.

Developers can’t push directly to the Release branch; their changes reach it only through an approved pull request.

Roles and Responsibilities

Team Lead

  • Responsible for creating the Master branch for a new product
  • Creates the Release branch for each sprint
  • Manages the CI/CD pipelines for the Release branch
  • Manages the branch policies
  • Mandatory reviewer for any code in the repository
  • Merges the Release branch to the Master branch
  • Release tagging
  • Responsible for keeping the Master branch locked until the final merge
  • Coordinates with the SDM (Service Delivery Manager) to get the release version number
  • Rebases from Master to the Release branch as and when there is a change in the Master branch
  • Deletes and recreates the Release branch for the new sprint
  • Identifies and trains a resource as a backup for the Team Lead

Developer

  • Responsible for creating the User Story branch
  • Manages the CI pipeline for the User Story branch
  • Initiates the pull request
  • Manages the inclusion of non-mandatory reviewers for the code review
  • Rebases from the Release branch to the User Story branch as and when there is a change in the Release branch
  • Upon completion of the story, merges the User Story branch to the Release branch
  • Deletes and recreates the User Story branch for the new user story

Reviewer

  • Ensures the quality of the source code according to the guidelines and best practices
  • Cancels or approves the pull request
  • Ensures meaningful review comments

Development Process

Setup

  1. The Team Lead creates the Release branch from the Master branch at the start of the sprint.
  2. The Team Lead sets the branch permissions for the Release branch.
  3. The Team Lead attaches CI/CD to the Release branch.
    • For the first time, the Team Lead creates the CI/CD pipelines pointing to the Release branch, and sets the build version number format in the build and release pipelines.
    • For later sprints, the pipeline is modified to source from the Release branch created for that sprint.
  4. The Developer creates a User Story branch from the Release branch.
  5. The Developer assigns reviewers for the branch.
  6. The Developer attaches the CI pipeline to the User Story branch.

Execution

  1. The Developer starts work on the branch.
  2. The Developer verifies the work on the development environment by running unit tests.
  3. If successful, the Developer checks in the code to the remote repository.
  4. Automated tests and code analysis validate the latest check-in.
  5. The process is repeated for the entire work needed for the story.
  6. Once the user story is complete, the Developer creates a pull request.

Build and Release

  1. The pull request automatically triggers CI, and only on successful validation is the pull request published.
  2. Reviewers do the code review and take suitable actions (cancel or approve the pull request).
  3. On approval, the Developer merges the branch with the Release branch.
  4. CI creates and versions the build.
  5. The build is automatically pushed to the development environment.
  6. After QA verification in the different environments, the Release branch is merged with the Master branch.
  7. After the release, a tag is created.
  8. The Release branch is deleted.
  9. The User Story branch is deleted.

For what happens to the build between steps 5 and 6 (the environments, approvals and quality gates), refer to the CI/CD Process series.

Commands for a day in the life of a developer

The following commands show how the above steps look in Git for a user story. Replace the input place holders with actual values.

# Create the user story branch from the sprint release branch
git checkout R_Sprint-021_2019-09-23
git pull origin R_Sprint-021_2019-09-23
git checkout -b S_12345_John_Change-in-all-environment

# Commit and push the work (CI runs on every push)
git add .
git commit -m "<summary of the change>"
git push -u origin S_12345_John_Change-in-all-environment

# Bring the latest release branch changes down to the user story branch
git fetch origin
git rebase origin/R_Sprint-021_2019-09-23
git push --force-with-lease

Once the story is complete, create the pull request from the user story branch to the release branch in Azure DevOps.

Must Be Aware: Rebase rewrites the commit history of the branch being rebased. It is safe for a user story branch, which only one developer works on (use --force-with-lease to push it). For a shared branch like the Release branch, coordinate with the team before rebasing it from Master, since everyone who has a local copy has to reset to the new history.

Azure DevOps Branch Policies

We apply the following Azure DevOps branch policies to the Release and Master branches,

Azure DevOps branch policies - minimum number of reviewers, linked work items, comment resolution and limited merge types
Azure DevOps branch policies - minimum number of reviewers, linked work items, comment resolution and limited merge types
PolicySettingWhy
Require a minimum number of reviewers2 reviewersAt least two people agree with every change
Check for linked work itemsRequiredEvery change can be traced to a user story or bug
Check for comment resolutionRequiredReview comments can’t be ignored
Limit merge typesBasic merge (no fast-forward) onlyThe history preserves exactly when each branch was merged
Build validationCI pipeline must succeedThe pull request is published only on successful CI (see the development process above)

Note: In the screenshot, “Requestors can approve their own changes” is enabled. Disable it when you want the two approvals to come from people other than the author.

Best Practices Recommendations

Code Review

Why we do code reviews,

  • To reduce the introduction of defects
  • To ensure that the code meets an acceptable quality level
  • To ensure that the code adheres to the project’s architecture, standards and best practices
  • To share and distribute knowledge

Reviewer

  • Always keep the focus on the code, not the developer.
  • Always be respectful. Don’t “talk down” to the developer. Don’t use any emotional language while discussing the code.
  • When making comments, it is very helpful to say whether you expect the comment to be addressed before the merge.
  • For any blockers, make sure that you communicate respectfully why they are blockers.
  • If you don’t feel like you have enough context to understand and merge the change, don’t hesitate to ask for an additional reviewer who has more context.

Pull Request

  • A pull request should be created only after the user story is complete, and it should contain changes just for that user story.
  • If you can split up a series of changes into multiple pull requests, consider doing so.
  • Feature additions which are somewhat independent of the original scope of the pull request should be raised separately.
  • What goes into a pull request is highly project-dependent.
  • Ideally, a pull request must be reviewed within two hours of the developer’s submission.

Small pull requests get better reviews. A reviewer can carefully go through 200 lines, but 2000 lines usually get an “LGTM” and a hope for the best.

Commit Message

  • Create insightful and descriptive commit messages.
  • The message should lead the reviewer to understand the change quickly without having to read the code.
  • When doing history archaeology to answer some questions, good commit messages likewise become very important.

Example:

Bad:  fixed bug
Good: Encode fund name in search results to prevent XSS (Bug 123)

Merge and Rebase

  • Before merging or rebasing, keep the local repository up to date by pulling any changes for the respective branches from the remote repository.
  • Rebase as often as possible to avoid merge conflicts later.

Wrap up

In this article, we have looked at the branch security roles, the responsibilities of the Team Lead, Developer and Reviewer, the step-by-step development process with the Git commands, the Azure DevOps branch policies and the best practices for code reviews, pull requests, commit messages, merge and rebase. I really appreciate that you took the time to read this article. In the next article, I will walk you through how we version our applications and libraries, how to trace a build back to the work items, and a complete sprint walkthrough which puts everything together.

Related Posts