Sobes.tech
Middle

How does your company handle branch merging or history rewriting (rebase) in the version control system?

sobes.tech AI

Answer from AI

In our team, we follow workflows based on Git. For integrating changes, we use two main approaches: merge and rebase, choosing them depending on the situation and branch type.

Merge:

  • Usually applied for merging long-lived branches, such as dev into main, or for integrating feature branches into dev.
  • Creates a merge commit that explicitly shows when changes from other branches were combined.
  • Preserves the full commit history, including all branches.
git checkout dev  // Switch to the target branch
git merge feature/new-feature  // Perform the merge of the feature branch

Rebase:

  • Used to keep a clean and linear commit history in feature branches until their integration (usually into dev).
  • Transfers commits of the current branch to the top of the target (dev) branch, effectively "rewriting" history.
  • Simplifies history, avoiding merge commits for each small feature or fix.
  • Important: Never rebase on public branches that other developers are working on, as this creates conflicts when pulling changes.
git checkout feature/new-feature  // Switch to the feature branch
git rebase dev  // Rebase feature commits onto dev
// Resolve conflicts if necessary
git push --force-with-lease  // Use --force-with-lease for safe push after rebase

Our standard workflow:

  1. A new feature or fix is developed in a separate branch (feature/..., fix/...).
  2. Periodically (before pull request or to sync with dev), the feature branch is rebased onto the current dev. This helps resolve conflicts early.
  3. After development and code review, the feature branch is merged into dev with no-ff (non-fast-forward) to preserve merge information. Or, less frequently, squashed into a single commit before merging into dev for very small features or fixes.
  4. From dev, releases are periodically made to main (Production branch), always using merge.

Thus, we balance the preservation of commit history (merge) with maintaining a clean development branch (rebase of feature branches).