<@ULVA73B9P> how do I add the branch to the follow...
# ask-marvin
r
@Marvin how do I add the branch to the following deployment cli command?
prefect-cloud deploy examples/hello.py:hello_world --from PrefectHQ/prefect-cloud
m
thought for 719.3 seconds
Short answer: you can’t add a branch to that command. In Prefect 3.x the correct CLI is
prefect deploy
(not
prefect-cloud deploy
), and there isn’t a `--from`/`--branch` flag. To deploy from a specific Git branch you have two good options: Option A — Use prefect.yaml with a git pull step (works with the CLI) 1) Add a pull step that specifies the repo and branch:
Copy code
name: my-project
deployments:
  - name: hello
    entrypoint: examples/hello.py:hello_world
    pull:
      - prefect.deployments.steps.git_clone:
          repository: <https://github.com/PrefectHQ/prefect-cloud>
          branch: my-branch
          # credentials: '{{ prefect.blocks.github-credentials.my-creds }}'  # if private
2) Run the deployment:
Copy code
prefect deploy
Docs: prefect.yaml pull action Option B — Use the Python API with from_source (fully remote, no local project)
Copy code
from prefect import flow
from prefect.storage import GitRepository

# reference a specific branch
source = GitRepository(
    url="<https://github.com/PrefectHQ/prefect-cloud>",
    branch="my-branch",
)

deployment = flow.from_source(
    source=source,
    entrypoint="examples/hello.py:hello_world",
)

deployment.deploy(
    name="hello",
    work_pool_name="your-work-pool",
)
Docs: Store flow code and deploy from source If you were hoping for a one-liner like
--from PrefectHQ/prefect-cloud@my-branch
, that isn’t supported in Prefect 3.x. The two patterns above are the supported ways to pin a branch. Quick check: are you on Prefect 3.x and okay switching from
prefect-cloud deploy
to
prefect deploy
or using the Python approach? I can help tailor the exact snippet to your setup.
n
@Marvin well there's a quickstart specific
prefect-cloud
CLI, which is probably not documented as well as it should be (our bad)
Copy code
@app.command(rich_help_panel="Deploy")
async def deploy(
    function: Annotated[
        str,
        typer.Argument(
            help="The path to the Python function to deploy in <path/to/file.py:function_name> format",
            show_default=False,
        ),
    ],
    repo: Annotated[
        str,
        typer.Option(
            "--from",
            "-f",
            default_factory=infer_repo_url,
            autocompletion=completions.complete_repo,
            help=(
                "GitHub repository reference in any of these formats:\n\n"
                "• owner/repo\n\n"
                "• owner/repo/tree/branch\n\n"
                "• owner/repo/tree/commit-sha\n\n"
                "If not provided, the repository of the current directory will be used."
            ),
            rich_help_panel="Source",
            show_default=False,
        ),
    ],
🙏 1
m
thought for 40.0 seconds
m
Got it — thanks for the context on the quickstart
prefect-cloud
CLI. To pin a branch with that CLI, use the
/tree/<branch-name>
form in the
--from
value. For your example:
Copy code
prefect-cloud deploy examples/hello.py:hello_world --from PrefectHQ/prefect-cloud/tree/my-branch
A few notes: - You can also pin a specific commit with
/tree/<commit-sha>
. - Short flag works too:
-f PrefectHQ/prefect-cloud/tree/my-branch
. - The
examples/hello.py:hello_world
path is resolved relative to the repo at that branch. If you tell me the branch name you want, I can paste the exact command back.
r
@Marvin While deploying with this syntax I received this error
Copy code
Traceback (most recent call last):
  File "/Users/ricardoibarra/.cache/uv/archive-v0/BNRkMbhGcPkRBf7at926j/lib/python3.13/site-packages/prefect_cloud/cli/utilities.py", line 127, in wrapper
    return fn(*args, **kwargs)
  File "/Users/ricardoibarra/.cache/uv/archive-v0/BNRkMbhGcPkRBf7at926j/lib/python3.13/site-packages/prefect_cloud/cli/utilities.py", line 165, in sync_fn
    return run_sync(async_fn(*args, **kwargs))
  File "/Users/ricardoibarra/.cache/uv/archive-v0/BNRkMbhGcPkRBf7at926j/lib/python3.13/site-packages/prefect_cloud/cli/utilities.py", line 308, in run_sync
    return ctx.run(loop.run_until_complete, coro)
           ~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.13/3.13.5/Frameworks/Python.framework/Versions/3.13/lib/python3.13/asyncio/base_events.py", line 725, in run_until_complete
    return future.result()
           ~~~~~~~~~~~~~^^
  File "/Users/ricardoibarra/.cache/uv/archive-v0/BNRkMbhGcPkRBf7at926j/lib/python3.13/site-packages/prefect_cloud/cli/deployments.py", line 271, in deploy
    deployment_id = await client.create_managed_deployment(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    ...<11 lines>...
    )
    ^
  File "/Users/ricardoibarra/.cache/uv/archive-v0/BNRkMbhGcPkRBf7at926j/lib/python3.13/site-packages/prefect_cloud/client.py", line 786, in create_managed_deployment
    deployment_id = await self.create_deployment(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    ...<8 lines>...
    )
    ^
  File "/Users/ricardoibarra/.cache/uv/archive-v0/BNRkMbhGcPkRBf7at926j/lib/python3.13/site-packages/prefect_cloud/client.py", line 348, in create_deployment
    raise RequestError(f"Malformed response: {response}")
httpx.RequestError: Malformed response: <Response [403 Forbidden]>
An error occurred.
m
thought for 159.3 seconds
Thanks for sharing the traceback — that 403 is coming back from the Prefect Cloud API when the quickstart
prefect-cloud
CLI tries to create a managed deployment. The branch syntax you used is fine; the error points to authorization or workspace/feature access, not the repo URL. Most common causes for 403 here: - You’re not logged in or your API key/workspace selection is stale - Your role in the workspace doesn’t have permission to create deployments - The quickstart “managed deployments” feature isn’t enabled for your account/workspace Quick checks 1) Re-auth and re-target the workspace explicitly
Copy code
prefect cloud login -k <YOUR_API_KEY> -w <account_handle>/<workspace_handle>
2) Confirm you’re on the intended profile
Copy code
prefect profile ls
Look for the star next to the active profile that’s configured for your Cloud workspace. 3) Verify permissions in that workspace You’ll need a role with deployment creation rights (e.g., Workspace Admin or a role with “Manage deployments”). If you’re on an account where the quickstart managed deployment feature isn’t enabled, this call will 403. Then retry:
Copy code
prefect-cloud deploy examples/hello.py:hello_world -f PrefectHQ/prefect-cloud/tree/my-branch
If the 403 persists - Can you share: - The exact command you ran (feel free to redact) - Your account/workspace handle - Your role in the workspace - Whether you can create a deployment using the standard CLI in the same workspace
Copy code
# prefect.yaml with git pull step
    name: quick-test
    deployments:
      - name: hello
        entrypoint: examples/hello.py:hello_world
        pull:
          - prefect.deployments.steps.git_clone:
              repository: <https://github.com/PrefectHQ/prefect-cloud>
              branch: my-branch
Then run:
Copy code
prefect deploy
- For additional detail, you can turn on debug logging and re-run to capture more context:
Copy code
PREFECT_LOGGING_LEVEL=DEBUG prefect-cloud deploy ...
Reference: - prefect.yaml pull step docs: prefect.yaml pull action If you prefer to bypass the quickstart CLI, the standard Prefect 3.x paths (prefect.yaml or Python
flow.from_source
with
GitRepository(branch="...")
) will let you pin a branch and create the deployment while we sort out the 403.
r
@Marvin Im using uvx for this, the issue seems to be that its connecting to another account but when I run uvx prefect-cloud logout and then uvx prefect-cloud login its not asking me the account, its just connecting by default to the previous one. How can I overwrite that old account using uvx
m
thought for 212.7 seconds
You’re right — uvx runs the tool in an ephemeral env, but it still reads/writes your Prefect profile in ~/.prefect, so it keeps reusing the previous Cloud account/workspace. Here are reliable ways to overwrite that old account when using uvx: Option 1: Force the workspace at login via the standard Prefect CLI This updates your active Prefect profile (which the quickstart CLI will pick up).
Copy code
uvx prefect cloud login -k <YOUR_API_KEY> -w <account_handle>/<workspace_handle>
uvx prefect profile ls   # confirm active profile (starred)
CLI help for reference:
Copy code
uvx prefect cloud login --help
# Options:
#   -k, --key TEXT           API Key
#   -w, --workspace TEXT     '<account_handle>/<workspace_handle>'
Option 2: Override via environment variables on the deploy command This bypasses whatever is saved in your profile.
Copy code
PREFECT_API_KEY=<YOUR_API_KEY> \
PREFECT_API_URL=<https://api.prefect.cloud/api/accounts/<account_id>/workspaces/<workspace_id>> \
uvx prefect-cloud deploy examples/hello.py:hello_world -f PrefectHQ/prefect-cloud/tree/my-branch
Tip: You can copy the account_id/workspace_id from the Cloud UI URL bar (it contains /accounts/<id>/workspaces/<id>). Option 3: Switch or clear your Prefect profile - List profiles:
Copy code
uvx prefect profile ls
- Switch to a different one (or after logging in above):
Copy code
uvx prefect profile use <profile_name>
- As a last resort, remove the saved config: - Close shells using Prefect, then delete ~/.prefect/profiles.toml (or remove the specific profile) and re-run Option 1. Option 4: Use the quickstart CLI’s login with explicit workspace (if supported) Run:
Copy code
uvx prefect-cloud login --help
If there’s a
--workspace
or
-w
option, do:
Copy code
uvx prefect-cloud logout
uvx prefect-cloud login -k <YOUR_API_KEY> -w <account_handle>/<workspace_handle>
Why this happens - uvx isolates packages, not your Prefect profile. The active profile in ~/.prefect (or env vars) determines which Cloud account/workspace all Prefect tools (including prefect-cloud) hit. If you share: - the handle you want (account/workspace) - whether you prefer login (Option 1/4) or env override (Option 2) …I’ll paste back the exact command(s) for your case.
n
i didn't read all this but fyi there's a top level
--profile
flag
prefect --profile local flow-run ls
etc
as in, perform this command as the
local
profile
r
Thanks @Nate I was able to login now by selecting another profile
@Marvin I'm now logged into the right account but when running
uvx prefect-cloud github setup
I'm getting this error:
Copy code
Traceback (most recent call last):
  File "/Users/ricardoibarra/.cache/uv/archive-v0/BNRkMbhGcPkRBf7at926j/lib/python3.13/site-packages/prefect_cloud/cli/utilities.py", line 127, in wrapper
    return fn(*args, **kwargs)
  File "/Users/ricardoibarra/.cache/uv/archive-v0/BNRkMbhGcPkRBf7at926j/lib/python3.13/site-packages/prefect_cloud/cli/utilities.py", line 165, in sync_fn
    return run_sync(async_fn(*args, **kwargs))
  File "/Users/ricardoibarra/.cache/uv/archive-v0/BNRkMbhGcPkRBf7at926j/lib/python3.13/site-packages/prefect_cloud/cli/utilities.py", line 308, in run_sync
    return ctx.run(loop.run_until_complete, coro)
           ~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.13/3.13.5/Frameworks/Python.framework/Versions/3.13/lib/python3.13/asyncio/base_events.py", line 725, in run_until_complete
    return future.result()
           ~~~~~~~~~~~~~^^
  File "/Users/ricardoibarra/.cache/uv/archive-v0/BNRkMbhGcPkRBf7at926j/lib/python3.13/site-packages/prefect_cloud/cli/github.py", line 25, in setup
    await install_github_app_interactively(client)
  File "/Users/ricardoibarra/.cache/uv/archive-v0/BNRkMbhGcPkRBf7at926j/lib/python3.13/site-packages/prefect_cloud/github.py", line 282, in install_github_app_interactively
    state_token = await client.get_github_state_token(
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        redirect_url=cloud_callback_url
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/Users/ricardoibarra/.cache/uv/archive-v0/BNRkMbhGcPkRBf7at926j/lib/python3.13/site-packages/prefect_cloud/client.py", line 158, in get_github_state_token
    response.raise_for_status()
    ~~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/Users/ricardoibarra/.cache/uv/archive-v0/BNRkMbhGcPkRBf7at926j/lib/python3.13/site-packages/httpx/_models.py", line 829, in raise_for_status
    raise HTTPStatusError(message, request=request, response=self)
httpx.HTTPStatusError: Client error '403 Forbidden' for url '<https://api.prefect.cloud/api/accounts/901b5d7c-926b-409d-bd3c-3bc95f8de244/integrations/github/state-token>'
For more information check: <https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/403>
m
thought for 110.0 seconds
Thanks — that stack trace is helpful. The 403 is coming from Prefect Cloud when the quickstart CLI tries to fetch a GitHub OAuth state token at: https://api.prefect.cloud/api/accounts/&lt;account_id&gt;/integrations/github/state-token That endpoint is account-scoped. In practice, 403 here almost always means one of: - Your user isn’t an Account Admin in that Prefect Cloud account (workspace roles aren’t enough for account-level integrations) - The GitHub integration/quickstart feature isn’t enabled for that account - You’re still pointed at a different account than the one you expect What to try 1) Confirm you’re on the right account/workspace - Open the UI and verify the account in the top-left switcher: https://app.prefect.cloud/ - From the CLI, confirm the target explicitly:
Copy code
uvx prefect cloud login -k <YOUR_API_KEY> -w <account_handle>/<workspace_handle>
  uvx prefect config view | grep PREFECT_API_URL
  uvx prefect profile ls
2) Check your role at the account level - In the UI, go to the target account → Settings → Members and verify your role. You typically need Account Admin to manage account integrations like GitHub. - If you don’t have admin, ask an Account Admin to run the setup or to grant you the role. 3) Try installing via the UI - In the UI, go to the same account → Settings → Integrations → GitHub and click Install/Configure. This will initiate the GitHub App installation. You’ll need GitHub org admin rights to complete it if you’re installing into an org. 4) If your account doesn’t have the GitHub quickstart feature - Reach out to your Prefect admin or support to enable the GitHub integration for your account. A 403 at that state-token endpoint can indicate the feature is not enabled for the account. Workaround if you want to proceed without the quickstart GitHub integration - You can still deploy from a Git branch using standard Prefect 3.x paths: - prefect.yaml + git_clone pull step:
Copy code
name: my-project
    deployments:
      - name: hello
        entrypoint: examples/hello.py:hello_world
        pull:
          - prefect.deployments.steps.git_clone:
              repository: <https://github.com/<owner>/<repo>>
              branch: <branch>
              # credentials: '{{ prefect.blocks.github-credentials.my-creds }}'  # if private
Deploy:
Copy code
uvx prefect deploy
- Or Python API with from_source:
Copy code
from prefect import flow
    from prefect.storage import GitRepository, GitCredentials

    source = GitRepository(
        url="<https://github.com/<owner>/<repo>.git>",
        branch="<branch>",
        # credentials=GitCredentials(token="<gh_pat>"),  # if private
    )

    d = flow.from_source(source=source, entrypoint="examples/hello.py:hello_world")
    d.deploy(name="hello", work_pool_name="your-work-pool")
If you can share: - Your Prefect Cloud account role - Whether you can see the GitHub integration under Settings → Integrations in the UI - The account handle you’re targeting …I can tailor the next step (UI path vs. enabling feature vs. CLI retry) and give you the exact commands or clicks to finish the setup.