Hey <@ULVA73B9P> I'm getting an error message whil...
# ask-marvin
r
Hey @Marvin I'm getting an error message while running my script that says:
Copy code
RuntimeError: Failed to clone repository with exit code 128.
This is the code:
Copy code
if __name__ == "__main__":
    
    # Check if required environment variables are set
    bc_access_token = os.environ.get("BC_ACCESS_TOKEN")
    
    github_repo = GitRepository(
        url="<github http url>",
        branch="main",
        credentials=GitHubCredentials(token=bc_access_token),
    )
I also test the PAT token access by connecting to it using the gh cli commands on mac and got this message:
Copy code
paste your authentication token: *********************************************************************************************
- gh config set -h <http://github.com|github.com> git_protocol https
✓ Configured git protocol
✓ Logged in as <user>
m
thought for 234.2 seconds
Thanks for the details — exit code 128 from git almost always points to an authentication or URL/config issue. A couple of quick clarifying questions to make sure we’re on the right path: - Which Prefect version are you using? (I’ll assume 3.x unless you say otherwise.) - What are your import statements for
GitRepository
and
GitHubCredentials
? (In Prefect 3.x, the typical path is to use the
git_clone
pull step with
prefect_github.GitHubCredentials
rather than a
GitRepository
class.) Why this is happening - The
gh
CLI login you tested is separate from
git clone
authentication. Unless your git is configured to use
gh auth git-credential
, a non-interactive
git clone
will not pick up
gh
auth. This is why
gh
can succeed but
git clone
(which Prefect uses under the hood) can fail with 128. - In Prefect 3.x, the recommended path is to either: - Use
Flow.from_source(...).deploy(...)
and configure pull steps for cloning, or - Call the
git_clone
pull step directly with an access token or a
GitHubCredentials
block. Fastest way to verify your token and URL on the same machine/container where the script runs - Run this quick Python test to isolate the issue:
Copy code
import os
from prefect.deployments.steps.pull import git_clone
from prefect_github import GitHubCredentials

# Make sure BC_ACCESS_TOKEN is set in THIS environment
token = os.environ.get("BC_ACCESS_TOKEN")
assert token, "BC_ACCESS_TOKEN not set in this environment"

git_clone(
    repository="<https://github.com/OWNER/REPO.git>",  # must be the full HTTPS URL
    branch="main",
    credentials=GitHubCredentials(token=token),
)
If this fails with 128, the error text in stderr usually clarifies whether it’s “authentication failed” or “repository not found”. Common fixes for exit code 128 in this context - URL must be HTTPS and include .git:
<https://github.com/owner/repo.git>
- Token scope/authorization: - For a classic PAT: ensure it has
repo
scope for private repos. - For a fine-grained PAT: ensure the token is granted access to the specific repo with at least “Contents: Read”. - If your org enforces SSO, make sure the token is SSO-authorized for that org. - Environment mismatch: ensure
BC_ACCESS_TOKEN
is set in the environment where the Prefect worker/process runs (containers often miss local env vars). - Don’t rely on
gh
auth unless you’ve configured git to use it: - You’d need
git config --global credential.helper '!gh auth git-credential'
for git to reuse
gh
auth. Otherwise, pass the token explicitly as shown above. - Submodules: if your repo has submodules and you set
include_submodules=True
, ensure those submodules also use HTTPS and are accessible with the same token. Recommended Prefect 3.x patterns - Programmatic pull (good for quick testing or ad hoc runs):
Copy code
from prefect.deployments.steps.pull import git_clone
from prefect_github import GitHubCredentials

git_clone(
    repository="<https://github.com/OWNER/REPO.git>",
    branch="main",
    credentials=GitHubCredentials(token=os.environ["BC_ACCESS_TOKEN"]),
)
- Deploy from source (recommended for deployments): - Use
Flow.from_source("<https://github.com/OWNER/REPO>", entrypoint="path/to/flow.py:my_flow")
then
deploy(...)
. - Provide credentials via your project’s pull step config (in
prefect.yaml
) using the same
git_clone
step and
GitHubCredentials
block. - Docs: - prefect-github integration - git pull steps API - prefect.yaml (deployments) If you can share: - Your Prefect version - Your imports for `GitRepository`/`GitHubCredentials` - The full stderr from the 128 failure (or run the short
git_clone
snippet above and paste the error) …I can pinpoint the exact fix.