﻿# bb dev servers: how branches avoid port collisions

A bb branch preview needs an explicit worktree-to-process-to-port mapping; separate Git files do not automatically separate all runtime resources.

Author: Retrivium editorial team
Updated: 2026-11-03
Canonical URL: https://retrivium.ai/journal/bb-devserver-worktree-port-collision/
Language: en

Separate branches can have separate files while their running applications still compete for the same port. A bb development setup becomes easier to inspect when each worktree has an identified dev-server address. The relationship between branch, directory, process and port is the central object of this arrangement.

## A checkout is only part of an environment

Git worktrees separate checked-out file states. They do not make every application select a different network port automatically. Imagine concurrent branches for a login fix and a settings redesign. Both can contain a valid startup command that uses the project’s default port. The first process can start successfully while the second reports an occupied address. The cause is shared runtime configuration, even though the branch names and source directories are correctly separated.

## Allocate an address for the actual process

The bb dev-server guide describes a per-worktree setup script and local port settings. The process must then use the selected value when it starts. Merely writing a configuration file does not prove that the application read it. For the example branches, a useful environment record connects each working directory to its listening address. An observed readiness response confirms the process is answering, while a project-specific page confirms that the response belongs to the expected application.

## Include dependent services in the mapping

A web frontend can still talk to an API launched from another branch. Giving the frontend a unique port is therefore necessary in some setups but insufficient to establish a fully independent application. Record the relevant API address and any test-data assumptions as well. This is an engineering extension of the environment mapping, not a guarantee that bb isolates every service. The useful boundary follows the request through the components that determine the behavior being inspected.

## Keep preview results connected to their branch

When a developer opens a private preview link, the route leads to a particular host and port. A later restart can change which process answers there. Preserve the current mapping in the report and refresh it after a meaningful environment change. The browser guide explains why reachability must be interpreted from the browser’s machine. With the mapping established, a screenshot or interaction result can be attributed to the intended branch rather than to whichever dev server happened to answer an old bookmark.

## Primary sources

- [Run a dev server for every branch](https://getbb.app/guides/remote-dev-servers).

- [Git worktree documentation](https://git-scm.com/docs/git-worktree).

- [Let your coding agent use a browser](https://getbb.app/guides/agent-browser).

Related engineering context: [Choosing an AI development stack](/journal/local-ai-app-stack-selection/); [Git state and undo](/journal/aider-git-dirty-tree-undo/).
