GCP DevOps Project
Sprint 01
Demo Setup Github repo according to DevOps best practice 02
Welcome back! In this lesson, we'll walk through enabling branch protection on GitHub and establish a workflow using feature branches and pull requests.
Enabling Branch Protection
Note
Enabling branch protection helps maintain code quality and prevents direct pushes to critical branches.
- In your repository, navigate to Settings > Branches.
- Click Add branch protection rule.
- Set Branch name pattern to
main
. - Enable Require a pull request before merging.
- Uncheck Require approvals if you're working solo.
- Scroll down and click Create.
Branch Protection Option | Description | Status |
---|---|---|
Require pull request before merging | Enforce all changes to go through a pull request | Enabled |
Require approvals | Mandate review approvals before merging | Disabled |
Once created, your protected rule appears in the list:
Working with Feature Branches
Warning
Avoid committing directly to main
. Always use a dedicated feature branch for your changes.
First, verify your current branch in VS Code:
git branch
* main
Creating a Feature Branch
Switch to a new branch for your task:
git checkout -b feature/task-02
git branch
* feature/task-02
main
Updating the README
- Open
README.md
. - Change the heading from
####
to#
for an H1 title. - Preview your changes to confirm the update.
Staging and Committing
Stage and commit the revision:
git add README.md
git status
# On branch feature/task-02
# Changes to be committed:
git commit -m "Update README.md to use H1 heading"
Pushing the Feature Branch
Push your branch to GitHub:
git push origin feature/task-02
You should see a message prompting you to create a pull request:
remote: Create a pull request for 'feature/task-02' on GitHub by visiting:
remote: https://github.com/learnwithraghu/gcp-devops-project/pull/new/feature/task-02
Creating and Merging a Pull Request
- Click Compare & pull request in the GitHub banner.
- On the Open a pull request page:
- Title: Update README.md to use H1 heading
- Description: Update the README file to make the first line a heading
- Review your changes and click Create pull request.
- Click Merge pull request, then Confirm merge (approvals are not required for solo projects).
After merging, your main
branch includes the change. This clear, repeatable process scales with team size and project complexity.
Links and References
That's it for this lesson. See you in the next one!
Watch Video
Watch video content