Skip to main content

Branching and Merging

Branching and merging in Diversion allows teams to work on multiple features in parallel while maintaining a stable main branch. With lightning-fast branch creation (milliseconds) and smart merging, Diversion makes parallel development effortless.

What are Branches?

A branch is an independent line of development in your repository. Branches allow you to:
  • Work on features without affecting the main codebase
  • Experiment with changes safely
  • Collaborate on separate tasks simultaneously
  • Maintain stable release versions while developing new features
Key characteristics in Diversion:
  • Branch creation takes milliseconds, regardless of repository size
  • Branches are server-side (cloud-based)
  • All team members can see all branches
  • No file copying or duplication

Understanding Branches vs Workspaces

Before diving into branching, it’s important to understand how branches relate to workspaces: Think of it this way:
  • Branch = Where the code lives (like main, feature-ui, bugfix-123)
  • Workspace = Your personal workbench (where you edit files locally)
Example workflow:
Learn more about workspaces →

Creating Branches

You can also create branches in the Desktop App.

Create a New Branch

Create a branch from your current position:
What happens:
  1. Diversion creates a new branch pointing to your current commit
  2. The branch is immediately available to all team members
  3. Creation takes ~100ms regardless of repository size
Example:

Create a Branch from a Specific Commit

List All Branches

Output example:
The * indicates your workspace’s current branch.

Switching Between Branches

You can also switch branches in the Desktop App.

Checkout a Branch

Switch your workspace to a different branch:
What happens:
  1. Diversion updates your workspace files to match the target branch
  2. Your local files change to reflect the branch’s state
  3. Any new commits will go to this branch
Example workflow:
Before switching branches:
  • Commit discard or shelf your current changes
  • Diversion will warn you if you have uncommitted changes
  • Use dv status to check for pending changes

Merging Branches

You can also merge branches in the Desktop App. Merging integrates changes from one branch into another. Diversion supports smart merging with automatic conflict detection.

Basic Merge Workflow

Goal: Merge feature-ui into main
1

Switch to target branch

First, check out the branch you want to merge into:
2

Merge the source branch

Merge the feature branch into main:
3

Resolve conflicts (if any)

If there are conflicts, Diversion will guide you through resolution:
4

Delete the feature branch (optional)

After merging, you can delete the feature branch:

How Merging Works

Diversion uses 3-way merge with common ancestor detection:
When you run dv merge feature-ui from main:
  1. Diversion finds the common ancestor (commit B)
  2. Compares changes from B→C (main’s changes)
  3. Compares changes from B→E (feature’s changes)
  4. Intelligently combines both sets of changes
  5. Creates a new merge commit:
Benefits:
  • Preserves history from both branches
  • Accurately detects conflicts
  • Maintains complete audit trail

Merge Strategies

Regular Merge (Default):
  • Preserves all commits from both branches
  • Creates a merge commit
  • Complete history visible in dv log
When to merge:
  • You want complete history
  • Feature commits are significant milestones
  • You need to track who made each change

Handling Merge Conflicts

The Desktop App provides a visual conflict resolution tool — see Merge Conflicts in the Desktop App. Merge conflicts occur when the same lines of code are changed in both branches.

Conflict Detection

Diversion prevents conflicts before they happen: Real-time notifications:
  • See who’s editing which files
  • Get notified when teammates modify files you’re working on
  • Coordinate changes before conflicts occur
Learn more about conflict prevention →

Resolving Conflicts

When conflicts do occur, Diversion makes resolution straightforward:
1

Identify conflicting files

2

Open conflicting files

Conflict markers show both versions:
3

Choose or combine changes

Edit the file to resolve the conflict:
4

Mark as resolved

Commit the resolved merge:

Conflict Resolution Options

Accept one side completely: Via Web UI or API:
  • Accept “ours” (keep main’s version)
  • Accept “theirs” (use feature branch’s version)
  • Accept all conflicts at once
Manual resolution:
  • Edit files to combine changes
  • Commit when satisfied

Branching Best Practices

1. Branch Naming Conventions

Use descriptive, consistent names: Good examples:
Naming patterns:
  • feature/ - New features
  • bugfix/ - Bug fixes
  • hotfix/ - Urgent production fixes
  • release/ - Release branches
  • experimental/ - Experimental work

2. Keep Branches Short-Lived

Why:
  • Reduces merge conflicts
  • Easier to review changes
  • Faster integration
How:
  • Merge feature branches within days, not weeks
  • Delete branches after merging
  • Create small, focused branches

3. Merge Frequently

Merge main into your feature branch regularly:
Benefits:
  • Smaller, easier merges
  • Catch conflicts early
  • Feature stays compatible with latest main

4. Use Descriptive Commit Messages

5. Delete Merged Branches

After merging, clean up:

Common Branching Workflows

Feature Branch Workflow

Best for: Teams developing multiple features simultaneously

Release Branch Workflow

Best for: Managing multiple release versions

Hotfix Workflow

Best for: Urgent production fixes

Troubleshooting

”Cannot switch branches: uncommitted changes”

Problem: You have uncommitted changes in your workspace. Solution:

“Merge conflict in multiple files”

Problem: Many files have conflicts. Solution:
  1. Resolve conflicts one file at a time
  2. Use dv status to track progress
  3. Consider accepting one side for non-critical files
  4. Manually merge important files

”Branch already exists”

Problem: Branch name is taken. Solution:

CLI Reference

Branch Management:
Merging:
Status:
Full CLI reference
Core Concepts: Workflows: CLI Reference:
Last updated: 2025-10-26