Tomás Rossetti
11/18/2025, 3:44 PMMarvin
11/18/2025, 3:45 PMNate
11/18/2025, 3:45 PMref to the pull step, which can be a commit hashTomás Rossetti
11/18/2025, 3:54 PMref. Also, ideally I would be able to use some predefined branch whenever I run but if I pass a hash ideally I'd overwrite that. But that may be too much to ask! @MarvinMarvin
11/18/2025, 3:54 PMNate
11/18/2025, 3:55 PMcommit_sha
https://github.com/prefecthq/prefect/blob/main/src/prefect/deployments/steps/pull.py#L103Marvin
11/18/2025, 3:55 PMpull:
- prefect.deployments.steps.pull.git_clone:
id: clone
repository: <https://github.com/owner/repo.git>
commit_sha: "{{ prefect.variables.target_sha }}"
# or: branch: "{{ prefect.variables.target_branch }}"
- Update before the run:
prefect variable set target_sha abc123def
Workers evaluate this at run time, so you can change it without redeploying.
- Docs: Prefect Variables, prefect.yaml, git_clone pull step
Option B: Environment variable placeholder in pull step
- prefect.yaml:
deployments:
- name: my-deploy
job_variables:
env:
GIT_SHA: "abc123def"
pull:
- prefect.deployments.steps.pull.git_clone:
repository: <https://github.com/owner/repo.git>
commit_sha: "{{ $GIT_SHA }}"
Ensure the env var is present in the worker’s runtime environment (job_variables.env or your work pool template). The pull step will use it when the worker executes.
- Docs: prefect.yaml, Customize job variables
Notes
- Passing a commit SHA as a flow parameter won’t work for code retrieval—the code is pulled/imported before parameters are read.
- If you prefer pinning at deploy time, set commit_sha on GitRepository when calling flow.from_source(...) (e.g., from an env var in CI); that value is then fixed for that deployment version.
- This works the same on Process, Docker, and Kubernetes workers; the git clone happens inside the worker at run time.
If you want to choose a commit per run from an external trigger/automation, I can share a tiny script/automation that sets the Prefect Variable and then schedules the run.Nate
11/18/2025, 3:55 PMNate
11/18/2025, 3:57 PMenv are runtime env values whereas commit_sha: "{{ $GIT_SHA }}" would template an env var $GIT_SHA on the machine running prefect deploy at deployment timeMarvin
11/18/2025, 3:57 PMTomás Rossetti
11/18/2025, 3:58 PMMarvin
11/18/2025, 4:02 PMprefect deploy depending on where they’re used, so they’re not a great fit for selecting code at run time. Prefect Variables avoid that ambiguity.
Example
pull:
- prefect.deployments.steps.pull.git_clone:
repository: <https://github.com/owner/repo.git>
commit_sha: "{{ prefect.variables.target_sha }}"
# or branch: "{{ prefect.variables.target_branch }}"
Set/change before a run:
prefect variable set target_sha abc123def
Relevant docs:
- Prefect Variables: Variables
- prefect.yaml behavior and pull steps: prefect.yaml
- git_clone step API: pull steps API
If you want, I can share a tiny script or automation pattern that sets target_sha and triggers the deployment in one go.Marvin
11/18/2025, 4:04 PMref parameter on Flow.from_source(...). That was a pattern you might have seen elsewhere; in 3.x you’ll use either:
- The Git clone step in a project’s prefect.yaml (CLI), or
- The GitRepository storage object with the Python API
Both support a default branch and an optional commit SHA; when both are provided the commit SHA wins (we clone the branch then checkout the SHA).
Option A — Projects (prefect deploy)
Use the built-in git clone step. You can set a default branch and optionally pin to a commit at deploy time via an environment variable.
prefect.yaml
name: my-project
prefect-version: ">=3.0.0"
pull:
- prefect.deployments.steps.pull.git_clone:
repository: "<https://github.com/acme/prefect-flows>"
branch: "main" # default branch
commit_sha: "{{ env.GIT_SHA | default('') }}" # optional SHA override
include_submodules: false
deployments:
- name: prod
entrypoint: flows/etl.py:etl
work_pool:
name: process-pool
Deploy:
# Use default branch
prefect deploy
# Pin to a specific commit for this build
GIT_SHA=abc1234 prefect deploy
Option B — Python API (flow.from_source(...).deploy(...))
Construct a GitRepository and pass it as the source. Set a default branch; optionally set a commit SHA when you want to pin.
from prefect import flow
from prefect.runner.storage import GitRepository
repo = GitRepository(
url="<https://github.com/acme/prefect-flows>",
branch="main", # default branch
commit_sha=None, # set to a SHA to pin
)
f = flow.from_source(repo, entrypoint="flows/etl.py:etl")
f.deploy(
name="prod",
work_pool_name="process-pool",
)
When you want to pin to a specific commit for a new deployment:
repo.commit_sha = "abc1234"
f.deploy(name="prod", work_pool_name="process-pool")
Can I override the ref at run time?
- Not as a first-class “run flag.” In 3.x the code source (branch/SHA) is part of the deployment’s storage configuration. To change what runs, update or create a deployment that points to the desired SHA/branch (you can do this programmatically and reuse the same deployment name, or create a temporary name per SHA).
- With Projects, the git_clone step happens at deploy/build time (not per flow run), so the override via GIT_SHA is also a deploy-time decision.
Quick references from the API we used:
- prefect.deployments.steps.pull.git_clone(repository, branch=None, commit_sha=None, ...)
- prefect.runner.storage.GitRepository(url, branch=None, commit_sha=None, ...)
- Flow.from_source(source, entrypoint) (no ref argument)
Which path are you using right now — the CLI/project (prefect deploy with a prefect.yaml) or the Python API (flow.from_source(...).deploy(...))? I can tailor the exact snippet to your setup.