Skip to content

Instantly share code, notes, and snippets.

@Attumm
Created February 23, 2025 12:46
Show Gist options
  • Select an option

  • Save Attumm/2fda8723caa0ba3d42f2d0cffadf31fa to your computer and use it in GitHub Desktop.

Select an option

Save Attumm/2fda8723caa0ba3d42f2d0cffadf31fa to your computer and use it in GitHub Desktop.

This git strategy focuses on maintaining stability and coherence in larger teams or open-source projects where versioning is crucial. Here's the gist of the idea: Create a pre-release branch: Instead of merging feature branches directly into main, create a pre-release branch (e.g., v2.0.0-pre-release) from main. Merge feature branches into pre-release: All development work (features, bug fixes) is merged into this pre-release branch. This allows developers to use normal git workflows (commit, push) on their individual branches. Continuous integration on pre-release: Run CI/CD pipelines against the pre-release branch. This ensures all new changes are tested together, simulating a real, fully-featured build. QA and testing: Use the pre-release branch for QA, acceptance testing, and user acceptance testing (UAT). This provides a more realistic testing environment with all features integrated. Merge request process: Instead of creating pull requests directly to main, developers create merge requests to the pre-release branch. This acts as a "squash for PRs," consolidating changes before they reach main. Finalize release: Once the pre-release branch is deemed ready (containing one or more completed features or fixes), merge it into main. Create version tag: After merging to main, create a version tag (e.g., v2.0.0) to mark the release point. Benefits of this approach: Maintains a stable main branch Allows for integrated testing of multiple features Provides a clear pre-release phase for thorough testing Simplifies version management with coherent tags Enables easier tracking of what changes are included in each release Facilitates writing comprehensive release notes This strategy emphasizes collaboration and integration testing, ensuring that all components work together before reaching the main branch. It's particularly suited for projects where stability and version control are paramount.

Document: Explanation of a Pre-Release Git Workflow: Branch-Level "Squash" for Stability

This document explains a Git workflow that uses a pre-release branch to achieve a form of "squash merging" at the branch level. This approach enhances release stability and simplifies change management, especially in team environments. It outlines how this workflow acts like a "git squash" but for entire branches, consolidating features before they become part of the main release.

Part 1: Understanding the Flow - Step-by-Step (Branch "Squash" Analogy)

This workflow is designed around the idea of a "branch-level squash," similar in principle to how git squash commit works for individual commits. It creates a consolidated and clean integration point before release:

  1. The main Branch: Clean, "Squashed" Release History: The main branch is like your final, polished release – it holds the official, released software in a clean and linear history, much like a branch with well-squashed commits. It's kept stable and reliable for users, benefiting from this "squashed" and consolidated history.

  2. Creating a Pre-Release Branch (vX.Y.Z-pre-release): The "Squashing" Area: Before each release, a "pre-release branch" (e.g., v2.0.0-pre-release) is created from main. Think of this branch as the area where we "squash" together all the feature branches. It's a staging area for the upcoming release, named with a version number and "-pre-release" to organize and define its purpose.

  3. Feature Branches (feat/new-feature): Individual Contributions: Developers work in separate "feature branches" to develop features or fixes. These branches might have many commits, representing the detailed development process of each feature.

  4. Merging to Pre-Release: "Squashing" Feature Branches: Completed feature branches are merged into the pre-release branch using merge requests. Crucially, these merge requests to the pre-release branch act as a form of "squash for branches." Just like git squash commit consolidates multiple commits into a single, cleaner commit, merging feature branches into pre-release consolidates potentially many commits of a feature into the pre-release branch, ready for integrated testing and a cleaner release.

  5. Testing on Pre-Release (CI/CD and QA): Validating the "Squashed" Integration: The pre-release branch, now containing the "squashed" integrations of features, is rigorously tested. CI/CD and QA processes ensure that these integrated, "squashed" features work well together and are release-ready.

  6. Finalizing Pre-Release: Ready for main - The Final "Squash" Destination: After testing confirms stability, the pre-release branch, with all its "squashed" feature integrations, is ready to be merged into main.

  7. Merging to main: Creating the "Squashed" Release: The validated pre-release branch is merged into the main branch. This merge operation takes the "squashed" and tested changes from pre-release and makes them the new, official release on main.

  8. Version Tag (vX.Y.Z): Marking the "Squashed" Release Point: A "version tag" is created on main to mark the specific commit that represents this "squashed," consolidated, and official release.

In Simple Terms: Develop features in separate branches → "Squash" merge features into a pre-release branch (like a branch-level git squash) → Test the "squashed" changes in pre-release → If tests pass, merge the "squashed" pre-release to main for the final, clean release.

Part 2: Why is this "Branch-Squash" Strategy Helpful? - Benefits of Consolidation

This Git strategy, using the pre-release branch as a "branch-level squash" mechanism, offers these key benefits:

  • main Branch with Clean, "Squashed" History: The main branch maintains a cleaner, more linear history, as features are integrated in a consolidated way via the pre-release branch. This "squashed" history on main improves readability and simplifies tools like git bisect.

  • Consolidated Feature Testing (Integration "Squashing"): The pre-release branch acts as the central point for consolidating and testing all features together. This "squashing" of features into the pre-release branch ensures comprehensive integration testing before release, catching issues early.

  • Clear, "Squashed" Release Units: Releases on main, resulting from merging the pre-release branch, represent well-defined and "squashed" units of change. Each release is a consolidated package of features that have been tested together in the pre-release stage.

  • Simplified Rollbacks and Version Tracking (Clean "Squash" History): The cleaner, more linear, and "squashed" history on main, along with version tags, simplifies version tracking and makes rollbacks to previous releases more straightforward and less error-prone.

  • Improved Traceability and Release Notes (Consolidated "Squash" View): The pre-release branch provides a clear, consolidated view of all changes going into a release (the "squashed" features). This simplifies understanding release content and writing accurate release notes.

In Summary: This strategy utilizes a pre-release branch to achieve a "branch-level squash" effect, consolidating feature changes before they reach the main release branch. This "squashing" action results in a cleaner project history, improved integration testing, and more reliable and manageable software releases, especially beneficial for collaborative projects.

Is this explanation, highlighting the "branch-level squash" analogy, now closer to what you were aiming for and more insightful? Please let me know your thoughts.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@Attumm

Attumm commented Mar 8, 2025

Copy link
Copy Markdown
Author

This system allows also for upgrading for instance.

One would start with patch

v2.0.1
During development it becomes clear that it's actually a minor

v2.1.0

Since both go from the main, one can simply create that branch and merge v2.0.1 into that one instead of main.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment