<@ULVA73B9P> I have a setup with two worker pools, one for production and one for development/testin...
o
@Marvin I have a setup with two worker pools, one for production and one for development/testing. I have created a GitHubRepository block in the UI, with no specific branch or tag in the "optional" reference field. I use this block in my deployments; source = GitHubRepository.load(_github_repo_block_name_) to_deploy = flow.from_source( source=source, entrypoint=entrypoint, ) My question is, is it possible to use this block for deployments pointing towards different branches inside the same repo, or do i need to/should create different blocks? How would I in case specify a specific branch for a block, either in the UI or programmatically?
m
thought for 415.4 seconds
Short answer - Yes, you can target different branches from the same repo — but not by “changing” a single saved block per deployment. - In Prefect 3.x, the recommended approach is to pass the branch (or commit SHA) on the source itself, typically by using
Flow.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
Copy code
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.