shlok
07/09/2025, 12:51 PMMarvin
07/09/2025, 12:51 PMMarvin
07/09/2025, 12:52 PMpython
if __name__ == "__main__":
flow.from_source(
source="<https://github.com/username/repository.git>",
entrypoint="path/to/your/flow.py:your_flow_function",
branch="your-branch-name" # Add this line to specify the branch
).deploy(
name="my-deployment",
work_pool_name="my-work-pool",
)
Simply add the branch
parameter to your from_source()
call. If you don't specify a branch, it will default to the repository's default branch (usually main
or master
).
For example, if you want to deploy from a branch called development
, you would write:
python
branch="development"
This is particularly useful when you want to:
- Test flows from development or feature branches
- Deploy different versions of your flows from different branches
- Maintain multiple versions of your flows in different branchesshlok
07/09/2025, 2:20 PMMarvin
07/09/2025, 2:20 PMMarvin
07/09/2025, 2:21 PMprefect deploy
command, here's what you need to do to ensure your changes take effect:
1. First, make sure you have a prefect.yaml
file in your project directory. This file should contain your deployment configuration. Here's how it should look:
yaml
deployments:
- name: "image-customization"
entrypoint: "image_customization.py:image_customization"
work_pool:
name: "local-pool"
source:
type: "github"
repository: "<https://github.com/calmtales/workflows.git>"
branch: "self-hosted"
credentials: "{{ prefect.github_credentials }}"
tags:
- "image-customization"
- "gcp"
2. Then, use the prefect deploy
command to update your deployment:
bash
prefect deploy
If you want to deploy a specific deployment from your yaml file:
bash
prefect deploy --name image-customization
3. To verify the update, you can:
- Check the deployment in the UI to see if the version has been updated
- Run prefect deployment ls
to see the current state of your deployments
- Use prefect deployment inspect image-customization
to see detailed information
If you're still not seeing your changes take effect, check these common issues:
- Ensure your git repository is up to date and changes are pushed to the correct branch
- Verify the branch name "self-hosted" is correct
- Confirm your GitHub credentials are properly configured
- Make sure there are no syntax errors in your prefect.yaml
file
You can also force a fresh deployment by first deleting the existing one:
bash
prefect deployment delete "image-customization"
prefect deploy
This will ensure you're starting with a completely fresh deployment rather than updating an existing one.shlok
07/09/2025, 2:27 PMMarvin
07/09/2025, 2:27 PMMarvin
07/09/2025, 2:28 PMpython
from prefect import flow, get_run_logger
@flow
def your_flow():
logger = get_run_logger()
<http://logger.info|logger.info>("Current working directory and git info:")
# Log git information
import subprocess
import os
try:
# Log the current branch
branch = subprocess.check_output(
['git', 'rev-parse', '--abbrev-ref', 'HEAD'],
stderr=subprocess.STDOUT
).decode().strip()
<http://logger.info|logger.info>(f"Current git branch: {branch}")
# Log the remote URL
remote = subprocess.check_output(
['git', 'remote', '-v'],
stderr=subprocess.STDOUT
).decode().strip()
<http://logger.info|logger.info>(f"Git remote info: {remote}")
# Log the last commit
commit = subprocess.check_output(
['git', 'log', '-1', '--oneline'],
stderr=subprocess.STDOUT
).decode().strip()
<http://logger.info|logger.info>(f"Latest commit: {commit}")
except subprocess.CalledProcessError as e:
logger.error(f"Error getting git info: {e.output.decode()}")
# Your existing flow code here
2. For more detailed debugging, you can set the Git environment variable to show more information during clone:
python
import os
from prefect import flow
@flow
def your_flow():
# Set git to be verbose
os.environ['GIT_TRACE'] = '1'
os.environ['GIT_CURL_VERBOSE'] = '1'
# Your existing flow code here
Additionally, you can verify the current deployment configuration using:
bash
prefect deployment inspect image-customization --json
This will show you the exact configuration being used, including the branch information.
If you're still having issues, you can try these troubleshooting steps:
1. Clear the Prefect deployment storage cache:
bash
rm -rf ~/.prefect/storage/*
2. Force a fresh clone by modifying your deployment code to include a pull-policy:
python
deployment = await flow.from_source(
source=GitRepository(
url="<https://github.com/calmtales/workflows.git>",
credentials=github_credentials,
pull_policy="ALWAYS" # Add this line to force fresh clone
),
entrypoint="image_customization.py:image_customization",
branch="self-hosted"
).deploy(
name="image-customization",
work_pool_name="local-pool",
tags=["image-customization", "gcp"],
)
3. You can also check the work pool logs for more detailed information about the deployment process:
bash
prefect work-pool ls
prefect work-pool preview local-pool
After adding these logging modifications, run your flow again and you should see which branch is being used during the clone step in the flow logs.shlok
07/09/2025, 2:32 PMMarvin
07/09/2025, 2:32 PMMarvin
07/09/2025, 2:32 PMMarvin
07/09/2025, 2:33 PMprefect.yaml
file explicitly sets the branch in the deployment configuration. It should look like this:
yaml
deployments:
- name: "image-customization"
entrypoint: "image_customization.py:image_customization"
work_pool:
name: "local-pool"
source:
type: "github"
repository: "<https://github.com/calmtales/workflows.git>"
branch: "self-hosted" # Make sure this is correct
credentials: "{{ prefect.blocks.github-credentials.github-token }}"
tags:
- "image-customization"
- "gcp"
2. Delete the existing deployment completely:
bash
prefect deployment delete "image-customization"
3. Clear the Prefect storage cache:
bash
rm -rf ~/.prefect/storage/*
4. Create the deployment fresh:
bash
prefect deploy
5. Verify the change took effect:
bash
prefect deployment inspect image-customization --json
If it's still not picking up the correct branch, you can try these additional steps:
1. Create a new deployment with a different name to avoid any caching issues:
yaml
deployments:
- name: "image-customization-v2" # New name
# ... rest of the configuration
2. Or, you can try setting the branch explicitly in the git clone step in your yaml:
yaml
deployments:
- name: "image-customization"
# ... other configuration ...
steps:
- prefect.deployments.steps.git_clone:
id: clone-step
repository: "<https://github.com/calmtales/workflows.git>"
credentials: "{{ prefect.blocks.github-credentials.github-token }}"
branch: "self-hosted"
After making these changes, deploy again and inspect to verify the branch has been updated. If you're still seeing the old branch, there might be a caching issue at the worker level. In that case, you might need to restart your worker as well:
bash
prefect worker stop
prefect worker start -p "local-pool"