DEV Community

Cover image for Reviving a Ruby Project with Git: Organizing Branches for Stability

Reviving a Ruby Project with Git: Organizing Branches for Stability

Ruby on Rails Developer

March 6, 2025

Introduction

Recently, I spent time bringing a Ruby project back on track. The project had a poor test suite and lacked code organization, leading to frequent deployment errors. One of the major issues was the disorganized branching strategy, which resulted in what I call "spaghetti branches." To ensure stability and minimize deployment errors, I decided to clean up and establish a consistent branch structure.

Need Expert Ruby on Rails Developers to Elevate Your Project?
Fill out our form! >>

Organizing the Branches

The project initially had both a develop and a main branch, but their usage was inconsistent. My goal was to:

Establish a clear separation between the stable and development branches.
Reduce errors caused by untested or incomplete pull requests.
Implement a structured workflow to make deployments more predictable.

Finding a Stable Starting Point

The first step was identifying a past stable version of the system. To do this, I searched the Git history for a commit when everything was working properly:

git log

Enter fullscreen mode Exit fullscreen mode

From the log, I located a commit SHA associated with a stable version of the project:

b0606efe6087be75e2ad7f19825dc5aba71ff0c2

Enter fullscreen mode Exit fullscreen mode

Using this commit, I created a new stable branch:

git branch stable-point
git reset --hard b0606efe6087be75e2ad7f19825dc5aba71ff0c2
Rebuilding the Main Branch
Enter fullscreen mode Exit fullscreen mode

To rebuild the main branch, I followed these steps:

First, switch to the latest active branch:

git switch latest-branch

Enter fullscreen mode Exit fullscreen mode

Create a new main branch:

git branch main
git switch main
Enter fullscreen mode Exit fullscreen mode

Perform an interactive rebase onto the stable point:

git rebase -i stable-point
Enter fullscreen mode Exit fullscreen mode

During this process, I carefully reviewed the commit history, removing untested or incomplete pull requests that required additional QA before merging into production.


📢 Need to Streamline Your Project?

Do you need to put your project in order, organize branches, isolate errors and bugs, or improve your test suite? I can help you implement efficient workflows and best practices to boost your development process.

💡 Let’s connect and optimize your project together!


Establishing a Reliable Workflow

With main now serving as the stable production branch, I introduced a structured branching model:

  • main branch → Used for production deployments.
  • develop branch → Created for staging and active development.

By maintaining this structure, we ensured that only tested and QA-approved changes reached production, while ongoing development work had a dedicated environment.

Conclusion

Cleaning up Git branches and establishing a structured workflow greatly improves stability and reduces deployment issues. By carefully selecting a stable commit, organizing branches logically, and using interactive rebasing to filter changes, we can bring even the most disorganized projects back on track.

This approach not only improves code quality but also makes collaboration more efficient and predictable, ensuring that future development proceeds smoothly without unnecessary deployment headaches.

https://rubystacknews.com/2025/03/06/reviving-a-ruby-project-with-git-organizing-branches-for-stability/

Top comments (0)