Space
The intelligent code collaboration platform
Space is pivoting to SpaceCode, focused on Git hosting and code reviews. Learn more →
Introducing the Space Git Flow
Do you strive to deliver quality code smoothly and steadily?
For development teams that practice a continuous release cycle, establishing a delivery flow can require significant effort when it comes to coordinating team members, setting up processes, and integrating multiple tools.
To reduce this burden, we’re introducing the JetBrains Space Git flow, a complete process that helps you achieve better code quality and keep your main branch green. Using it, you can focus on development while ensuring your main stays stable as you implement changes.
Space provides you with Git hosting, code reviews, quality gates, and a CI/CD service on a single platform. Implementing the Space Git flow in your projects is easy, allowing you to control changes automatically and keep your codebase production-ready.
In this blog post, we’ll discuss branching strategies, introduce you to the Space Git flow, and demonstrate how it can be used in a project.
Choosing a Branching Strategy
The branching strategy you select for your team affects your code safety, feature release frequency, and speed of delivery, making this choice crucial to your development process.
There are several branching strategies that teams commonly use, including Git flow, feature branches, and trunk-based development. Among these strategies, Git flow or variants thereof are the most popular approaches. Here’s a short overview of the most popular branching strategies.
Git flow
Git flow is a branching strategy useful for teams that have clear release processes and need to keep their production environments stable. The reliance on multiple branches and rules, however, adds a lot of complexity to the process. This can be overwhelming for new team members and can lead to conflicts because of the failure to comply with continuous integration principles.
GitHub flow
GitHub flow is a lightweight branching strategy well-suited to teams that practice continuous deployment. This strategy emphasizes collaboration, frequent releases, and a streamlined development process. Given its simplicity, GitHub flow works best for small teams and projects. However, as size and complexity increase, it can become challenging to manage changes across the entire codebase with this flow.
Trunk-based development
Trunk-based development is a branching model where developers collaborate on code in a single branch called trunk
. This strategy requires direct pushes to trunk
and collaboration among developers to maintain a stable trunk
branch. Since changes are continuously integrated into the trunk
, there is a higher risk of introducing changes that can impact the stability of the entire system.
How to choose a branching strategy
Each strategy has its own strengths and weaknesses, and the best choice depends on the specific needs of your team, as well as factors such as the team’s size, development process, deployment frequency, and code quality requirements.
Understanding the pros and cons of each strategy can help your team make informed decisions about which approach to use. While you can implement almost any flow in Space, we recommend that you consider employing a strategy native to it – the Space Git flow.
Introducing the Space Git Flow
What is the Space Git flow?
The Space Git flow is a branching strategy that is similar to GitHub flow, but with a greater emphasis on safety when making changes to the main
branch and the ability to scale to large projects and teams. In JetBrains, we use this flow for many of our products, including Space itself.
The main elements of the Space Git flow are outlined below. Though most of the items are optional, the more you implement, the closer you will be to having the best and safest flow possible.
Main branch
A single main
branch is always production-ready – the tests are green, and all changes are verified. The main
branch is protected, meaning direct commits are not allowed.
Feature branches
Changes to the code are made in a separate feature
branch. Always create your feature
branches from main
.
Merge requests and quality gates
To merge changes from a feature
branch into main
, you create a merge request that must pass through quality gates. Quality gates, which can be customized to fit your team’s workflow, are sets of conditions that have to be met in order to merge:
- Approval in a turn-based code review. A reviewer comments on the code and passes the turn to the author to make revisions until the changes are finally approved by the reviewer.
- A successfully completed Space Automation job.
- An external check, which passes if an external CI/CD service like TeamCity reports that the build is successful.
Safe Merge
Safe Merge is an additional safety step before finally merging changes from a feature
branch into main
. Space creates a temporary merge commit with the latest changes from both branches and uses it to perform quality checks with an Automation job or TeamCity build. If the checks are successful, the changes from feature
are finally merged into main
.
Release branches
If your project involves public releases, you should use release
branches created from main
. If necessary, last-minute changes are cherry-picked from main
to a particular release
branch.
Why use the Space Git flow?
The Space Git flow brings multiple benefits to your team and the development process. You can even get a feel for these benefits without going all-in, as JetBrains Space can mirror your existing Git repository without having to migrate. You can switch back any time.
Using the Space Git flow allows you to:
- Configure quality gates to achieve higher-quality code and a stable, protected
main
branch, with:
- Safe Merge for feature branches.
- Code owners for mandatory reviews in critical code areas.
- Space Automation or TeamCity build status as quality gate criteria for merge requests.
- Introduce a code review process your team will love:
- Review code from IntelliJ IDEA with its native Space integration.
- Perform code reviews on the go with Space iOS and Android applications.
- Keep your code reviews in order and up to date with a clear turn-based review model.
The Space Git Flow in Action
Let’s have a look at how you can use the Space Git flow in action. Here’s a short video that summarizes how it works when integrated with TeamCity:
Want to learn more? See how the Space Git flow works in more detail below.
Host or mirror your Git repository in Space
You can use Space to host your source code or mirror your repository from GitHub or another Git service in a few clicks.
Protect main
from accidental pushes
To prevent accidental pushes to the main
branch, set up branch protection in Space and enable quality gates.
Once you’ve set it up, the only way a change can make it to main
is through a merge request.
Create a feature branch
To start working on a new feature, you’ll need to either clone the repository to your machine or use remote development with the IDE hosted on a virtual machine in the Space cloud.
From your IDE, you can make changes to your code in a separate branch, add a commit message, and then push this branch back to Space.
Before merging it back to main
, you will need to request a code review from your teammates.
Create a merge request
Create a merge request to begin the process of moving your new code into main
. You can do this from within your JetBrains IDE using the native integration, or you can find your branch in Space and create a merge request from there.
You can set a title and description for your merge request and see the commits that will be part of it. The quality gates require at least one person to review these changes.
Space will require a review based on code ownership
In your repository, you can create a special file named CODEOWNERS
that specifies who is responsible for specific folders and files. Later, you and your colleagues will be able to select a code owner to review your changes as a part of quality gates.
Wait for your team to review the changes
Now you can wait for your colleagues to review the changes. They can add comments and suggestions, or they can simply approve the request. After you’ve agreed on changes, you can proceed with merging them.
You can manage code reviews in Space, from your IDE, or on the go with the Space iOS and Android apps.
Ensure your build is green
With Space, there are a few options that you can use to make sure your build is green. You can use both of them for extra security.
Run CI/CD checks
After you create a merge request, Space Automation and/or CI jobs are triggered to validate the changes by building the code and running tests. As part of quality gates, the changes will be merged into main
only if a CI/CD server can successfully build the feature
branch.
The checks can be set and completed by both Space Automation and an external CI/CD service, like TeamCity.
These checks, however, only ensure the new code is valid and integrates well with the main
branch at the time of branching. With Safe Merge, validation is done by attempting to integrate the new code with the very latest code from the main
branch.
Run Safe Merge
You can use Safe Merge before merging the changes directly into main
. Safe Merge acts like a time machine – it runs a preview of what your main
branch would look like with the changes.
This can be especially useful for large projects because while you were working on a feature
branch, the main
branch could have received changes that conflict with your work. Safe Merge allows you to catch these conflicts before actually merging the branches.
Space creates a temporary commit and triggers a CI/CD build in Space Automation or Teamcity. The changes are merged into the main
branch only if the build succeeds. Otherwise, the merge is rejected.
Using Git hosting, code reviews, and CI/CD together in the Space Git flow ensures that changes to your application’s code base are always reviewed. And thanks to Safe Merge, you’ll always have a main
branch that compiles and can be deployed successfully.
How to Get Started With the Space Git Flow
Starting with the Space Git flow is easy, as no migration is required. Just mirror your repository in a few clicks. You can always switch back at any time.
Ready to give it a try?
- Create a Space organization if you don’t have one yet.
- Check out this step-by-step tutorial to configure the Space Git flow using Space Automation or TeamCity.
- Request a demo to ask questions or get help tuning the flow to your specific process.
What do you think about the Space Git flow? We’d love your feedback in the comments below.