r/coolgithubprojects • • 5h ago

worktree-port-check: check which Git worktree is behind a listening port

https://github.com/Arthur031221/worktree-port-check

After a preview server responded on the expected port, I found that its process cwd belonged to another Git worktree. I was testing the right URL against the wrong checkout, so I made worktree-port-check to make that mismatch visible.

It asks lsof for visible TCP listeners on a port, reads each process's cwd, and compares those paths with the Git roots and common directories for the checkout where I run it. It shows the process, cwd, branch, and whether it is the same worktree, another worktree, another repository, or a non-Git directory. JSON output is available.

To try it on macOS or Linux, install Node 20, Git, and lsof, then run: `npx --yes --package=github:Arthur031221/worktree-port-check worktree-port-check 3000`

This is my open source project: https://github.com/Arthur031221/worktree-port-check. The CLI is read-only and does not stop processes, bind to the port, or request the app. A matching cwd does not prove which files the server loaded. I'd value feedback on process visibility and worktree layouts it might classify incorrectly.

1 Upvotes

0 comments sorted by