GCP DevOps Project
Sprint 01
Task 3Setup Github repo according to DevOps best practice
In this guide, we'll walk through configuring your GitHub repository to align with DevOps best practices. You'll learn how to protect your main
branch, enforce pull request reviews, and adopt a scalable workflow for collaborative development.
Current Workflow and Its Drawbacks
Most teams begin with a simple process:
- Clone the central repo.
- Make changes directly on
main
. - Push updates back to
main
.
While straightforward, this method introduces two critical issues:
- Unreviewed code: Bugs or security flaws can reach production unvetted.
- Frequent merge conflicts: Multiple direct pushes to
main
often collide.
To solve these problems, we’ll enable branch protection and mandate pull requests.
Enabling Branch Protection Rules
Branch protection rules block direct pushes to critical branches (like main
) and enforce quality checks before merging.
Key Branch Protection Settings
Rule | Description | Benefit |
---|---|---|
Require pull request reviews | Prevents direct commits to main | Ensures code is peer-reviewed |
Enforce status checks | CI/CD pipelines must pass | Avoids broken or failing builds |
Dismiss stale approvals | Forces fresh reviews after changes | Keeps feedback up to date |
Note
Configure branch protection under Settings > Branches in your GitHub repository. For details, see GitHub Branch Protection.
With these rules enabled:
- Direct pushes to
main
are blocked. - All changes must go through a pull request.
- Required CI/CD checks must be green before merging.
Recommended GitHub Workflow
Adopt a feature-branch workflow to scale collaboration:
- Clone the repository locally.
- Create a new feature branch:
feature/your-feature-name
. - Commit work to the feature branch.
- Push the branch and open a pull request against
main
. - Request reviews and address feedback.
- Merge when approvals and checks are complete.
# 1. Clone the repo
git clone https://github.com/your-org/your-repo.git
cd your-repo
# 2. Create and switch to a feature branch
git checkout -b feature/your-feature-name
# 3. Stage and commit your changes
git add .
git commit -m "Add description of your feature or fix"
# 4. Push and publish the branch
git push -u origin feature/your-feature-name
After pushing, navigate to the GitHub UI to open a pull request and assign reviewers.
Warning
Avoid emergency fixes directly on main
. Even urgent patches should follow the pull request process to maintain auditability.
What’s Next?
In the next article, we’ll demonstrate how to apply branch protection rules in the GitHub settings and manage pull requests step by step.
Watch Video
Watch video content