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
- 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:| Concept | Purpose | Visibility | Typical Lifespan |
|---|---|---|---|
| Branch | Independent line of development | All team members | Days to weeks |
| Workspace | Your local working environment | Only you | Entire project duration |
- Branch = Where the code lives (like
main,feature-ui,bugfix-123) - Workspace = Your personal workbench (where you edit files locally)
Creating Branches
Create a New Branch
Create a branch from your current position:- Diversion creates a new branch pointing to your current commit
- The branch is immediately available to all team members
- Creation takes ~100ms regardless of repository size
Create a Branch from a Specific Commit
List All Branches
* indicates your workspace’s current branch.
Switching Between Branches
Checkout a Branch
Switch your workspace to a different branch:- Diversion updates your workspace files to match the target branch
- Your local files change to reflect the branch’s state
- Any new commits will go to this branch
Merging Branches
Merging integrates changes from one branch into another. Diversion supports smart merging with automatic conflict detection.Basic Merge Workflow
Goal: Mergefeature-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:dv merge feature-ui from main:
- Diversion finds the common ancestor (commit B)
- Compares changes from B→C (main’s changes)
- Compares changes from B→E (feature’s changes)
- Intelligently combines both sets of changes
- Creates a new merge commit:
- 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
- You want complete history
- Feature commits are significant milestones
- You need to track who made each change
Handling Merge Conflicts
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
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
- Edit files to combine changes
- Commit when satisfied
Branching Best Practices
1. Branch Naming Conventions
Use descriptive, consistent names: Good examples:feature/- New featuresbugfix/- Bug fixeshotfix/- Urgent production fixesrelease/- Release branchesexperimental/- Experimental work
2. Keep Branches Short-Lived
Why:- Reduces merge conflicts
- Easier to review changes
- Faster integration
- Merge feature branches within days, not weeks
- Delete branches after merging
- Create small, focused branches
3. Merge Frequently
Mergemain into your feature branch regularly:
- 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 simultaneouslyRelease Branch Workflow
Best for: Managing multiple release versionsHotfix Workflow
Best for: Urgent production fixesTroubleshooting
”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:- Resolve conflicts one file at a time
- Use
dv statusto track progress - Consider accepting one side for non-critical files
- Manually merge important files
”Branch already exists”
Problem: Branch name is taken. Solution:CLI Reference
Branch Management:Related Resources
Core Concepts: Workflows: CLI Reference:Last updated: 2025-10-26

