AZ-400: Designing and Implementing Microsoft DevOps Solutions

Branching Strategies for Source Code

Azure Repos collaborating with pull requests

This lesson provides a comprehensive guide to the pull request process in Azure Repos. You'll learn how to create a feature branch, review and comment on changes, and merge the final code—all essential steps for efficient code collaboration.

The demonstration begins with the administrator logged in under the KodeKloud GitHub account. After confirming that the application repository and build pipeline are correctly set up, we introduce Lloyd from the KodeKloud GIFs team. Lloyd will create a feature branch, make changes to update the front page text, and then initiate a pull request.

Creating a Feature Branch and Making Changes

Lloyd opens Visual Studio Code and creates a new branch named “ChangeFrontPage” to update the front page text. The branch is created with the following command:

git checkout -b ChangeFrontPage
# Output:
# Switched to a new branch 'ChangeFrontPage'

After switching to the new branch, Lloyd edits the front page file (home.razor) and checks the file status:

git status

The output confirms that the home.razor file has been modified. Next, the changes are added, committed, and pushed to the remote repository on Azure Repos. Once the push is successful, the new branch is available for collaboration.

When Jeremy Morgan, the repository administrator, checks the repository branches, the new feature branch may not be immediately visible. However, when Lloyd logs in, he can see the "ChangeFrontPage" branch:

The image shows a screenshot of the Azure DevOps interface displaying the branches of a repository named "KodeKloudGifts." It lists two branches, "ChangeFrontPage" and "master," along with details like commit IDs, authors, and status.

Creating a Pull Request

With the feature branch pushed, Lloyd creates a pull request. He provides a title and description—"Change front page text"—and assigns Jeremy Morgan as a reviewer. The pull request lists the modified files and commit details, with the ultimate goal of merging the "ChangeFrontPage" branch into the master branch.

The image shows a screenshot of a new pull request being created in Azure DevOps, with fields for the title, description, and reviewers. The pull request is for merging changes from the "ChangeFrontPage" branch into the "master" branch.

Due to repository permissions, Jeremy Morgan holds the approval authority. Viewing the pull request details from the administrator's perspective provides further insight:

The image shows a pull request page in Azure DevOps for a project named "KodeKloudGifts," with details about changes to the front page text and no merge conflicts.

Reviewing and Commenting on the Pull Request

Jeremy reviews the pull request to ensure that the changes—merging "ChangeFrontPage" into master—are correct and conflict-free. Additional reviewers can be added if further validation is required (for example, including a reviewer like Jen). Reviewers can leave comments or ask questions, such as verifying if the updated text has been reviewed by legal.

Here's an example of the updated home page code under review:

<h1>Kode Kloud Gift Shop</h1>
<p>Welcome to the Kode Kloud Gift Shop, where you can find the quirkiest and most unique gifts at unbeatable prices! Whether you're looking for a gift for a friend, family member, or even yourself!</p>

The image shows a pull request in Azure DevOps for a project named "KodeKloudGifts," with a change to the "Home.razor" file. The change involves updating text on the front page.

In the file comparison view, reviewers observe that the old text is still present in home.razor until the merge is finalized:

@page "/"
<PageTitle>Home</PageTitle>
<h1>Kode Kloud Gift Shop</h1>
Welcome to the KodeKloud gift shop!

Once all reviewers are satisfied with the modifications, they approve the pull request using options like "Approve with suggestions," "Wait for author," "Reject," or "Decline to review" depending on the review policies.

The image shows a pull request interface in Azure DevOps, where a user is reviewing changes to the front page text. There are comments and options to approve or reject the changes.

Merging the Pull Request

After approval, the final step is to complete the pull request. Developers have access to several merge strategies:

• Merge (No Fast-Forward)
• Squash Commit (creates a linear history with a single commit)
• Rebase and Fast-Forward (rebases the feature branch commits onto master)
• Semi-linear Merge

Merge Strategy

For this demonstration, the "Merge, No Fast-Forward" strategy is employed. This approach allows for a customizable merge commit message, completion of associated work items, and the option to delete the feature branch based on organizational policies.

Once merged, the changes are reflected in the home.razor file, and the continuous integration pipeline automatically builds and deploys the updates.

Conclusion

This lesson has provided an overview of the pull request workflow in Azure Repos, covering:

• Creation of a feature branch
• Making and reviewing code changes
• Initiating a pull request
• Merging changes into the master branch

Understanding this workflow is essential for managing code changes efficiently. For further learning, consider exploring our certification lab exercises.

Thank you for reviewing this lesson. Stay tuned for more articles on enhancing your development workflow and collaboration strategies.

Watch Video

Watch video content

Previous
Collaborate with pull requests