Knowing how to create a branch in GitHub is just the beginning. What really matters is making sure that what you merge is secure, compliant, and reviewable. In this post, we’ll walk through the full process: how to create a branch in GitHub, how to merge branches in GitHub securely, how to cancel merge in GitHub if risks are found, and how Xygeni helps you see every issue before it hits your main branch.
Let’s walk through it step by step.
1. How to Create a Branch in GitHub the Right Way
Every secure workflow starts when you create a branch in GitHub. It allows developers to isolate features, fixes, or experiments without impacting the production code.
To create a branch in GitHub:
1. Navigate to your repository
2. Click the branch selector dropdown
3. Type the name of your new branch
4. Click Create branch
From here, your new branch is ready to go. You can now push code, collaborate on changes, and eventually open a pull request. Although this is a basic GitHub action, it sets the stage for secure development.
Notably, every time you create a branch in GitHub, it should be part of a repeatable and protected workflow.
2. Scan Pull Requests Automatically Before You Merge
Once the work is done, it’s time to open a pull request. But before merging, it is essential to verify that the code does not introduce vulnerabilities. A single unsafe commit can expose your application, leak secrets, or break critical infrastructure.
Merging code into your main branch is a high-impact operation. Without proper checks in place, it can lead to serious consequences such as:
- Zero-day vulnerabilities slipping into production
- Known CVEs introduced through open source packages
- Hardcoded secrets pushed to the repository
- Infrastructure misconfigurations that weaken your defenses
- Malicious or tampered code entering through dependencies
This is where Xygeni makes a real difference
By using GitHub Actions, you can trigger automated Xygeni scans whenever a developer opens a pull request into a protected branch. A protected branch in GitHub is one that requires specific checks or approvals before changes are allowed to merge.
Xygeni analyzes the latest execution of the pull request workflow to validate the security posture of the proposed changes. This includes checking for issues in the code, dependencies, secrets, and CI/CD configurations. The full branch is not re-scanned, but the most recent workflow result is used to enforce policies and block unsafe merges.
These scans validate that the code is secure and production-ready. They detect:
- Code vulnerabilities (SAST)
- Vulnerable open source packages (SCA)
- Hardcoded secrets
- IaC misconfigurations
- Potential malware
Integrating these checks early ensures that every time you create a branch in GitHub and prepare to merge, you do it with full visibility and control.
Here’s a simplified setup:
on:
pull_request:
branches: [ main ]
jobs:
xygeni-scan:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Xygeni Scanner
uses: xygeni/xygeni-action@3.2.0
with:
token: ${{ secrets.XYGENI_TOKEN }}
3. Block Insecure Merges with Guardrails
With Guardrails, Xygeni gives you full control over what gets merged. You can define precise rules tailored to your security policies and risk tolerance. For example:
- Block if a critical secret is found (e.g., AWS keys, tokens)
- Fail the build if a new high-risk open source package is introduced
- Reject pull requests that modify sensitive paths like
.github/workflows/
,infrastructure/
, orsecrets.env
- Prevent merges if a downgrade reintroduces known vulnerabilities
- Block CI/CD configuration changes unless properly labeled
- Stop merges if SAST detects high or critical issues
- Apply stricter Guardrails on production branches while keeping flexibility in development
These rules act as automated gatekeepers. They help your team merge only what’s secure, no surprises, no manual reviews, no last-minute firefighting.
Example Guardrail rule:
guardrail block_critical_secrets
on secrets
when severity = critical
then @fail()
Visual Feedback in the Dashboard
To ensure full visibility, Xygeni shows the result of latest evaluation of the Guardrail status:
- Green icon: All policies passed
- Red icon: One or more Guardrail conditions were violated
This gives both developers and security teams immediate insight into why a merge was blocked, without digging into CI logs.
Real Example from the Dashboard:
Let’s say a repository has no protected branches, a common misconfiguration that allows developers to push commits without verification. That’s a serious risk.
Xygeni automatically detects and flags this as a signed_commits issue under the CI/CD category. The dashboard highlights:
- Severity: High
- Type: Signed Commits
- Explanation: The repository has no protected branches
- Status: Open
With this context-rich feedback, teams can quickly identify the risk, understand its impact, and take corrective action, all from the Xygeni UI.
Customize Enforcement Behavior
You’re always in control. Choose how strict Guardrails should be:
--fail-on=critical
: Block merges only on severe findings--never-fail
: Run Guardrails in dry-run mode to test policies before enforcing
So next time you create a branch in GitHub, your Guardrails are already there, protecting your pipeline and enforcing your policies automatically.
How Do I Know If a GitHub App Is Safe?
Learn how to evaluate GitHub Apps before installing them.
4. Cancel Merge in GitHub Automatically When Risks Are Found
If a scan or Guardrail fails, the pull request is blocked from merging.
Xygeni integrates directly into GitHub’s UI. When a risk is found:
- GitHub shows the check as failed
- GitHub’s protections prevent the merge
- The merge queue skips insecure code
Whether it’s a secret, CVE, or dangerous CI/CD pattern, the result is the same: the merge is canceled in GitHub and flagged for review.
You can also view detailed results in Xygeni:
- The security status of each branch
- Why a merge was blocked
- Complete scan history
- Guardrail status shown via green (pass) or red (fail) icons in the project page
This visual feedback makes it easy for developers and security teams to take action with confidence. And when you need deeper context, each issue links to documentation with severity, tags, location, and mitigation guidance.
Tldr Merge Only What’s Safe
To summarize, here’s how to merge securely after you create a branch in GitHub:
- Create a branch in GitHub through the UI
- Trigger automatic scans with every pull request with Xygeni
- Block insecure merges using Guardrails
- Use server-side audit policies for deeper control
- Cancel merge in GitHub when something fails
- Visualize all results in Xygeni’s dashboard
Although merging is a basic operation, doing it securely requires real visibility and automation. With Xygeni, you don’t just merge code, you merge trust.
Protect Every GitHub Branch with Confidence
A single overlooked issue in a pull request can compromise your main branch. Traditional scanners often run too late, miss critical risks, or fail to enforce meaningful policies.
That is why protecting your GitHub branches takes more than just scanning.
Xygeni provides real enforcement. When a pull request targets a protected branch, Xygeni analyzes the latest execution of your CI/CD workflow. It does not re-scan the entire branch. Instead, it evaluates the most recent results to check for security issues in code, dependencies, secrets, and workflow configurations. You are not just alerted. You are protected.
What makes it different:
- Full-context validation: Guardrails enforce policy using rich context like severity, exploitability, and branch metadata.
- Built-in GitHub integration: Everything from scanning to enforcement runs natively within your GitHub workflows, with no need for custom scripts or glue code.
- Server-side audits: After upload, results are validated again using server-side Guardrails, providing a second layer of control outside the pipeline.
Instead of relying on your CI setup to catch everything, Xygeni applies automated, policy-based decisions before anything reaches your main branch.
With Xygeni, protecting your GitHub branches is not a separate step. It is part of your workflow.