Loading page...Загружаем страницу...正在加载页面...
AtlasRepo

When a preview port belongs to the wrong Git worktree

说明与用途

worktree-port-check 能识别监听指定端口的服务器属于哪个 Git 检出,揭示预期与实际代码库之间的不匹配。

问题

A development server may listen on the expected port while running from a different Git checkout, causing confusion when inspecting the wrong code base.

结果

The tool successfully identified that a server listening on port 3000 was running from a different Git checkout, allowing the developer to correct the environment.

工作流

  • 1. Run npx --yes --package=github:Arthur031221/worktree-port-check worktree-port-check 3000 to scan port 3000.
  • 2. The tool queries lsof for TCP listeners on the port.
  • 3. For each listener, it reads the process cwd and asks Git for the checkout root and common directory.
  • 4. It compares roots and common directories to determine if the listener belongs to the same, a linked worktree, or a different repository.
  • 5. The tool reports the findings, including branch names for context.
  • 6. Exit codes indicate whether a listener belongs to another checkout (1) or if information is incomplete (4).

证据

I built worktree-port-check to compare the checkout in my terminal with the current directory of every visible process listening on one TCP port.

来源

The command asks lsof for TCP listeners on the selected port. It reads the cwd for each visible process, then asks Git for the checkout root and common directory at that path.

来源

Exit code 1 means a visible listener belongs to another checkout. Exit code 4 means the inspection did not have enough information to reach a complete result.

来源

  • 记录日期: 2026-10-03T21:40:46.331Z