Olve Heitmann
09/14/2025, 11:17 AMMarvin
09/14/2025, 11:17 AMMarvin
09/14/2025, 11:24 AMFlow.from_source(...) with a GitRepository object.
- If you prefer using blocks in the UI, create separate block documents per branch (e.g., one with Reference=main, another with Reference=develop) and select the appropriate block per deployment.
A bit more detail and options
1) Preferred (no block): specify branch/commit programmatically
- Construct a GitRepository with a branch or commit_sha and pass it to Flow.from_source(...).
- This lets you easily deploy the same flow to prod/dev with different refs without managing multiple blocks.
Example
from prefect import flow
from prefect.storage import GitRepository
@flow
def my_flow():
...
# Dev/test branch
dev_source = GitRepository(
url="<https://github.com/owner/repo>",
branch="develop", # or commit_sha="abc123"
# credentials=..., # optional: token or Git credentials block
)
Flow.from_source(source=dev_source, entrypoint="path/to/flow.py:my_flow").deploy(
name="my-flow-dev",
work_pool_name="dev-pool",
)
# Prod pinned to main or a release SHA
prod_source = GitRepository(
url="<https://github.com/owner/repo>",
branch="main", # or commit_sha="release-sha"
)
Flow.from_source(source=prod_source, entrypoint="path/to/flow.py:my_flow").deploy(
name="my-flow-prod",
work_pool_name="prod-pool",
)
2) If you want to keep using your GitHubRepository block from the UI
- Set the block’s “Reference” field to the branch, tag, or commit SHA you want. One block = one ref.
- For different branches, create separate blocks (e.g., my-repo-main, my-repo-develop) and select the appropriate one when you create each deployment.
- There isn’t a clean way to reuse a single saved block document and “override” its reference per-deployment on the fly.
Why this is recommended
- In Prefect 3.x, the general guidance is to deploy “from source” rather than relying on GitHub storage blocks. Programmatic GitRepository usage gives you precise control over branch/commit and clean separation between dev and prod.
- For production, pinning to a commit_sha is safer and fully reproducible. For dev/testing, using a branch is usually fine.
Docs
- GitHub integration overview and blocks: Prefect GitHub integration
If you’d like, share how you’re authoring deployments (Python vs. UI/CLI), and I can show the exact steps that match your workflow.Bring your towel and join one of the fastest growing data communities. Welcome to our second-generation open source orchestration platform, a completely rethought approach to dataflow automation.
Powered by