Virtual Branches
Virtual branches are one of ProGit’s most powerful features. They let you work on multiple features simultaneously without the friction of constantly switching git branches.
The Problem
Section titled “The Problem”Traditional git workflow:
# Working on feature Agit checkout -b feature-a# ... write code ...
# Emergency bugfix neededgit stashgit checkout -b hotfix# ... fix bug ...git checkout feature-agit stash pop# Hope the stash applies cleanly...Problems:
- Context switching is slow
- Stashes can conflict
- Hard to see work-in-progress across branches
- Easy to forget about stashed work
The Solution: Virtual Branches
Section titled “The Solution: Virtual Branches”Virtual branches exist only in ProGit’s tracking layer, not in git itself:
Git Branches: main ──────────────────────────────
Virtual Branches (ProGit): ├─ feature-auth [WIP: 3 files] ├─ feature-ui [WIP: 1 file] └─ hotfix-memory [WIP: 2 files]Creating Virtual Branches
Section titled “Creating Virtual Branches”# Create a new virtual branchprogit branch virtual feature-auth
# Or from the TUI (press 'b', then 'v')How It Works
Section titled “How It Works”File-Level Tracking
Section titled “File-Level Tracking”ProGit tracks which files belong to which virtual branch:
Working Directory:├── src/│ ├── auth.rs ← feature-auth│ ├── login.rs ← feature-auth│ ├── ui.rs ← feature-ui│ └── widget.rs ← feature-ui├── fix/│ └── memory.rs ← hotfix-memory└── Cargo.toml ← sharedSwitching Between Work
Section titled “Switching Between Work”# Switch to feature-auth workprogit branch switch feature-auth
# Now only feature-auth files are "visible"$ ls src/auth.rs login.rs
# Edit, commit, etc.vim src/auth.rsgit add src/auth.rsgit commit -m "Add OAuth support"
# Switch to different workprogit branch switch feature-ui
# Now feature-ui files are visible$ ls src/ui.rs widget.rsVisual Representation
Section titled “Visual Representation”In the ProGit TUI (press b for branches):
┌─ Virtual Branches ─────────────────────┐│ ││ ▶ feature-auth 3 files, 2 commits││ feature-ui 1 file, 0 commits ││ hotfix-memory 2 files, 1 commit ││ ││ [a]ctive [c]reate [d]elete [m]erge ││ │└────────────────────────────────────────┘Committing Virtual Branch Work
Section titled “Committing Virtual Branch Work”When you’re ready to commit a virtual branch:
# Option 1: Commit as new git branchprogit branch commit feature-auth --as-branch# Creates git branch 'feature-auth' with your changes
# Option 2: Commit to existing git branchprogit branch commit feature-auth --to-branch=main# Squashes and commits to main
# Option 3: Create a PR/MRprogit branch commit feature-auth --mr# Creates merge request on GitLabConflict Detection
Section titled “Conflict Detection”Virtual branches can touch the same files:
# feature-auth modifies src/main.rs# feature-ui also modifies src/main.rs
$ progit branch switch feature-ui⚠ Conflict detected with feature-auth
File: src/main.rs feature-auth: lines 42-50 modified feature-ui: lines 45-55 modified
[v]iew conflict [s]tash changes [a]bortBest Practices
Section titled “Best Practices”1. Keep Virtual Branches Small
Section titled “1. Keep Virtual Branches Small”# Good: Focused virtual branchesprogit branch virtual feature-login-pageprogit branch virtual feature-oauth-backendprogit branch virtual fix-typo
# Avoid: Monolithic virtual branchesprogit branch virtual everything2. Commit Regularly
Section titled “2. Commit Regularly”# Commit virtual branch work to git branches oftenprogit branch commit feature-auth --as-branchgit push origin feature-auth
# This backs up your work3. Use Descriptive Names
Section titled “3. Use Descriptive Names”# Goodprogit branch virtual feature/user-authprogit branch virtual hotfix/memory-leak
# Avoidprogit branch virtual tempprogit branch virtual wip4. Clean Up Completed Work
Section titled “4. Clean Up Completed Work”# Delete virtual branch after mergingprogit branch delete feature-authIntegration with Issues
Section titled “Integration with Issues”Link virtual branches to issues:
# Create virtual branch from issueprogit issue branch 42 --virtual# Creates virtual branch linked to issue #42
# See related work in TUIprogit tui# Issue panel shows linked virtual branchConfiguration
Section titled “Configuration”[git.virtual_branches]# Enable virtual branchesenabled = true
# Maximum concurrent virtual branchesmax_concurrent = 5
# Auto-commit when switching awayauto_commit = false
# Show conflict warningsconflict_warnings = true
# Default git branch for commitsdefault_target = "main"Comparison with Git Worktrees
Section titled “Comparison with Git Worktrees”| Feature | Virtual Branches | Git Worktrees |
|---|---|---|
| Multiple checkouts | ✅ Yes | ✅ Yes |
| Disk usage | Lightweight (metadata only) | Heavy (full copy) |
| Switching speed | Instant | Fast |
| IDE support | Native | Requires setup |
| Visual overview | Built-in TUI | Manual |
| Conflict handling | Automatic detection | Manual |
Example Workflow
Section titled “Example Workflow”# Morning: Start three tasksprogit branch virtual feature-apiprogit branch virtual feature-uiprogit branch virtual refactor-tests
# Work on APIprogit branch switch feature-apivim src/api.rsgit add src/api.rsgit commit -m "Add endpoint"
# Quick context switch to UIprogit branch switch feature-uivim src/ui.rs
# Emergency bugfixprogit branch switch maingit checkout -b hotfixvim src/fix.rsgit commit -m "Hotfix"
# Back to API workprogit branch switch feature-api# Your API changes are still there!
# End of day: Commit virtual branchesprogit branch commit feature-api --as-branchgit push origin feature-api