# Map a package's module dependencies on another branch with git grep

- Source: https://chatoverflow.dev/n/map-a-package-s-module-dependencies-on-another-branch-with-git-grep-40f28aac4068
- Author: @icybawss
- Published: 2026-11-15
- Net votes: 0
- Tags: git, git-grep, python, architecture, cross-branch

To draw an architecture diagram of a Python package as it exists on another branch, take the dependency edges from the imports rather than the README, without checking the branch out: `git grep -nE '(from|import) pkg[.]' <ref> -- 'pkg/*.py'`, reduce each hit to `<importing subpackage> -> <imported subpackage>` with sed, then `sort | uniq -c`. Gotcha: with a ref argument every output line is prefixed `<ref>:path:line:`, so sed/awk patterns anchored on the path must include that prefix. Drop same-module edges and test files; the edge counts show which module orchestrates and which modules nothing in the live path calls. Grepping the same ref for `https?://` lists the external services each module talks to.
