Part II — Intermediate Development · Chapter 11 · Lesson 3 of 6 · 6 min read
Lesson 3: Local, Git, and Registry Sources
Lesson level: Intermediate
Purpose: Learn how a dependency can be declared from a local path, a Git repository, or a registry, and what each source can and cannot guarantee about reproducibility and trust.
Release note: commands, field names, and syntax in this lesson are illustrative. Verify them against your installed v0.63 release before relying on them.
Learning objectives
By the end of this lesson, you should be able to:
- Declare a dependency from a local path, a Git repository, and a registry.
- Explain the difference between mutable and immutable references.
- Describe how the lock records each source.
- Choose the right source for development, review, and release.
- Identify portability and trust risks before adopting a source.
3.1 Why the source matters
A version constraint says which versions are acceptable. The source says where the code comes from. Two packages with the same name and version can differ in content if they come from different places, so the source is part of the dependency identity.
3.2 Local path sources
A local path source points to a directory on disk. It is the fastest way to develop a library and its consumer together. In the running example, order_rules can use a sibling checkout of input_checks while you change both.
[dependencies]
input_checks = { path = "../input_checks" }
A path source has no version history of its own. Its content is whatever is on disk at that moment, so it cannot be reproduced on another machine unless the same directory exists there.
3.3 Git sources
A Git source names a repository URL and a reference. The reference can be a branch, a tag, or a commit.
[dependencies]
input_checks = { git = "https://example.com/team/input_checks.git", tag = "v1.2.0" }
test_helpers = { git = "https://example.com/team/test_helpers.git", rev = "9f3c2ab" }
A branch moves every time someone pushes. A tag should not move but can be rewritten. A full commit identifier cannot change, so it is the strongest Git reference.
3.4 Registry sources
A registry source uses a name and a version constraint, as in Lesson 1. The registry resolves the constraint to a published release. Releases are normally immutable once published, and they can carry checksums and signatures, which Lesson 5 covers.
[dependencies]
input_checks = "^1.2.0"
3.5 Comparing the three sources
| Source | Typical use | Reference stability | Portable | Integrity evidence |
|---|---|---|---|---|
| Local path | Co-developing a library | None: reflects disk state | No | None |
| Git, branch | Following a team branch | Moves on every push | Yes, if reachable | Commit recorded in lock |
| Git, tag | Release candidates | Stable by convention | Yes, if reachable | Commit recorded in lock |
| Git, commit | Strict pinning | Immutable | Yes, if reachable | Commit identifier |
| Registry | Released packages | Immutable releases | Yes | Checksum and signature |
3.6 Choosing a source
- Use a path source only while developing locally, and never in a release.
- Use a Git commit or tag when a package is not yet published.
- Use a registry source for anything you ship or share.
3.7 Mixing sources in one project
A project can use all three sources at once. Keep the mix deliberate. A common pattern is a path source on a developer branch, replaced by a registry version before merging.
3.8 Mutable and immutable references
A mutable reference can point to different content tomorrow. An immutable reference cannot. Ask of every dependency: if I resolve this again next month, can I get different code?
| Reference | Mutable? | Risk |
|---|---|---|
| Path | Yes | Content changes silently |
| Branch | Yes | Upstream push changes your build |
| Tag | Rarely | Tag can be moved or deleted |
| Commit | No | Low |
| Registry release | No | Low; yanked releases may disappear |
3.9 How the lock records sources
The lock from Lesson 2 stores the resolved source for each package. For Git it stores the exact commit, even when the manifest names a branch. For a registry it stores the version and checksum. For a path it stores only the path.
[[package]]
name = "input_checks"
version = "1.2.3"
source = "git+https://example.com/team/input_checks.git#9f3c2ab"
This is why a branch dependency is reproducible only while the lock is kept. Running an update re-resolves the branch to a new commit.
3.10 Portability of path sources
An absolute path such as a home directory fails on every other machine. A relative path works only when the directory layout matches. Treat path sources as a local convenience and keep them out of shared branches.
3.11 Trust and review
- A Git host proves where code came from, not that it is safe.
- A registry can add checksums and signatures, which a Git source usually lacks.
- Review the diff before moving a pinned commit or tag.
- Record why each non-registry source exists.
3.12 Worked example
The order_rules project needs a fix in input_checks that is not yet published. The team pins a commit while the fix is reviewed.
[dependencies]
input_checks = { git = "https://example.com/team/input_checks.git", rev = "9f3c2ab" }
When version 1.2.4 is published, the team switches back to the registry and removes the Git entry.
[dependencies]
input_checks = "^1.2.4"
3.13 Offline and mirrored environments
Locked builds on restricted networks need the sources to be reachable. Registry mirrors and internal Git hosts keep builds working. Confirm that the mirror serves the same content as the original, using the checksum or commit recorded in the lock.
3.14 Inspecting sources
pea tree
pea lock --check
pea install --locked
Use these illustrative commands to list where each package comes from, confirm the lock matches the manifest, and install exactly what the lock records.
3.15 Source policy for a team
- Release branches allow only registry sources.
- Git sources must use a commit or tag.
- Path sources are rejected in continuous integration.
3.16 Common mistakes
| Mistake | Consequence | Fix |
|---|---|---|
| Committing a path dependency | Build fails on other machines | Use a registry or Git source before merging |
| Depending on a branch without a lock | Builds change without notice | Commit the lock or pin a commit |
| Trusting a tag as permanent | Tag is moved and content changes | Pin the commit |
| Mixing sources without a reason | Hard-to-audit dependency graph | Document each exception |
3.17 Guided practice
- Declare input_checks as a path source and run the tests.
- Change it to a Git tag and note what the lock records.
- Change it to a commit and compare the lock entry.
- Switch to the registry constraint ^1.2.0 and compare.
3.18 Hands-on lab
Take the order_rules project through all three source types and record, for each, the manifest entry, the lock entry, and whether a clean checkout on another machine would reproduce the build.
Deliverable: a one-page table of the three sources with your reproducibility findings.
3.19 Review questions
- Why is the source part of a dependency identity?
- Which Git reference is immutable?
- What does the lock store for a branch dependency?
- Why are path sources unsuitable for releases?
- What evidence can a registry offer that Git cannot?
3.20 Applied challenge
Write a source policy for a team of five that allows path sources locally, requires pinned Git references for unpublished packages, and enforces registry-only dependencies on release branches. Describe how you would check each rule automatically.
Lesson summary
- Local, Git, and registry sources trade convenience against reproducibility.
- Immutable references and recorded locks make builds repeatable.
- Registries add integrity evidence; paths and branches add risk.
Transition to Lesson 4
Where a package comes from is only part of the picture. Lesson 4 covers permission manifests, archives, installation, and auditing: what a package is allowed to do and how you inspect it.
Lesson status: Ready for review.