Git Sync
Git Sync keeps the server's workflows in a Git repository. A pull copies DAG files, the scripts and templates they use, Wiki pages, Wiki attachments, and business calendars from a branch into Dagu. A publish commits edits made in Dagu and pushes them to the same branch.
A pull never overwrites a file that was changed in Dagu. That file becomes a conflict for you to resolve.
Set Up
Add
git_synctoconfig.yaml:yamlgit_sync: enabled: true repository: github.com/acme/automation branch: main path: workflows # omit to use the repository root auth: type: token token_file: /run/secrets/git-token auto_sync: enabled: true interval: 300 # secondsRestart the server.
Pull once and check the result:
bashdagu sync pull dagu sync status
With auto_sync.enabled, the server pulls when it starts and then every interval seconds. Without it, pull from the Git Sync page or with dagu sync pull.
Repository Layout
Dagu reads only the files under git_sync.path and places each one by its location:
repository/
└── workflows/ git_sync.path
├── daily-report.yaml → paths.dags_dir
├── scripts/generate.py → paths.dags_dir/scripts
├── calendars/jp-banking.yaml → paths.calendars_dir
└── wiki/ → paths.wiki_dir
├── operations/runbook.md
└── .attachments/…Each synced file is an item with an ID and a kind. The web UI, dagu sync, and the REST API name items by ID:
| Repository file | Kind | Item ID |
|---|---|---|
daily-report.yaml | dag | daily-report |
scripts/generate.py | file | scripts/generate.py |
calendars/jp-banking.yaml | calendar | calendars/jp-banking |
wiki/operations/runbook.md | doc | wiki/operations/runbook |
wiki/.attachments/operations/runbook/chart.png | doc-asset | wiki/.attachments/operations/runbook/chart.png |
DAG, calendar, and Wiki page IDs drop the .yaml, .yml, or .md extension. Other IDs keep the full path.
- DAGs:
.yamland.ymlfiles, exceptbase.yaml, which is never synced. - Calendars:
calendars/<name>.yamldirectly under the path. Deeper files undercalendars/are DAGs or supporting files. - Wiki: Markdown files under
wiki/. A repository that hasdocs/and nowiki/keeps usingdocs/. A repository with both fails to pull. - Supporting files: every other regular file, such as scripts, SQL, templates, certificates, and binaries. The executable bit is kept.
- Not synced: symlinks, submodules, and files outside
git_sync.path.
Two files that map to the same ID, such as report.yaml and report.yml, fail the pull before anything is written.
Set the path in a shared repository
A pull copies every supporting file under git_sync.path into paths.dags_dir. In a repository that holds other code, set path to the workflows directory.
Pull, Edit, and Publish
| Status | Meaning |
|---|---|
synced | Matches the last pulled or published version. |
modified | Changed in Dagu since then. |
untracked | Created in Dagu and never published. |
conflict | Changed in Dagu and in the repository, or changed in Dagu and deleted in the repository. |
missing | Tracked, but the local file is gone. |
On a pull:
- Files that are
syncedtake the repository's version. modifiedfiles keep the local edit. If the repository also changed them, they becomeconflict.- A file deleted in the repository is deleted locally when it is unchanged, and becomes
conflictwhen it was edited. Empty directories left behind are removed. untrackedfiles are left alone.
To publish, select items on the Git Sync page, or run dagu sync publish. Dagu commits them as commit.author_name and pushes to branch. If the push fails, the commit is rolled back.
To resolve a conflict, compare the two versions in the diff view, then either discard the local copy to take the repository's version, or publish with force to replace the repository's version.
Dagu finds new DAG files, Wiki pages, attachments, and calendars created on the server. It does not find new supporting files. Commit those to the repository and pull.
Read-Only Servers
Set push_enabled: false on a server that should only follow a branch, such as production:
git_sync:
enabled: true
repository: github.com/acme/automation
branch: production
push_enabled: false
auto_sync:
enabled: true
interval: 60The server then refuses every change to DAGs and calendars from the web UI and API, and every Git Sync action there, including pull. It takes new commits through auto-sync, and dagu sync pull on the server host pulls on demand. Promote reviewed commits between branches as described in Multi-Environment Deployments.
Supporting Files in Workflows
Set working_dir: . so a step runs from the directory that holds the DAG file:
working_dir: .
steps:
- id: generate
run: python scripts/generate.py --template templates/summary.htmlOn a distributed worker, the files are not there. List them under dependencies so the worker receives a copy:
steps:
- id: generate
run: python scripts/generate.py --template templates/summary.html
dependencies:
- scripts/generate.py
- templates/summary.htmlThe worker still needs the runtime, such as Python. See File Dependencies.
Node Inventories
Set git_sync.inventory_path to keep the server's node inventories in the repository. The path starts at the repository root, not at git_sync.path. The file is a JSON array in the format that dagu nodes export prints.
repository/
├── workflows/ git_sync.path
│ └── deploy.yaml
└── inventories/
├── staging.json inventory_path on the staging server
└── production.json inventory_path on the production serverEach server names its own file, so staging and production run the same workflows against different hosts. To start, export the current inventories and commit the file:
dagu nodes export > inventories/production.jsonAfter every pull, Dagu makes the inventories match the file:
- An inventory in the file replaces the one with the same name, compared without case, and keeps its ID. A new name creates an inventory.
- An inventory that is not in the file is deleted.
- The whole file is checked first, as
dagu nodes importchecks it. If the file is invalid or missing, the pull fails and no inventory changes. - The check runs even when the repository has not changed, so the next pull undoes edits made on the Nodes page or with
dagu nodes. Edit the file instead. - Dagu never writes the file, and it is not a sync item.
- Trusted host keys are not part of an inventory. Pin each node's key with
host_keyin the file. A node that keeps its name keeps any key already trusted for it.
dagu sync pull prints Node inventories updated when a pull changed them. Without inventory_path, Git Sync leaves the inventories alone.
Authentication
git_sync:
repository: github.com/acme/automation
auth:
type: token
token_file: /run/secrets/git-token # or token: ${GITHUB_TOKEN}git_sync:
repository: git@github.com:acme/automation.git
auth:
type: ssh
ssh_key_path: /home/dagu/.ssh/id_ed25519
ssh_passphrase_file: /run/secrets/ssh-passphraseA repository without a scheme, such as github.com/acme/automation, is cloned over HTTPS. Set ssh_passphrase_file only for a key that has a passphrase. For an SSH user other than git, put it in the URL: deploy@git.example.com:acme/automation.git.
token_file and ssh_passphrase_file read the secret from a file, such as a mounted Docker or Kubernetes secret. Do not set both forms of one secret. See Secrets From Files.
Configuration Reference
Every key has an environment variable: git_sync.auto_sync.interval is DAGU_GITSYNC_AUTOSYNC_INTERVAL, and git_sync.auth.token_file is DAGU_GITSYNC_AUTH_TOKEN_FILE.
| Key | Default | Description |
|---|---|---|
enabled | false | Turns on Git Sync. |
repository | none | github.com/org/repo, or an https://, http://, ssh://, or git@ URL. |
branch | main | Branch to pull from and push to. |
path | repository root | Subdirectory that holds the Dagu files. |
inventory_path | none | JSON file of node inventories, from the repository root. |
push_enabled | true | false makes the server read-only. |
auth.type | none | token or ssh. |
auth.token, auth.token_file | none | Access token, or a file that holds it. |
auth.ssh_key_path | none | SSH private key. |
auth.ssh_passphrase, auth.ssh_passphrase_file | none | Passphrase of the key, or a file that holds it. |
auto_sync.enabled | false | Pull in the background while the server runs. |
auto_sync.on_startup | true | With auto-sync, pull when the server starts. |
auto_sync.interval | 300 | Seconds between background pulls. 0 pulls only at startup. |
commit.author_name | Dagu | Author of published commits. |
commit.author_email | dagu@localhost | Author email of published commits. |
Permissions
Treat the repository as code that runs on the server. Review changes before they reach the synced branch, limit who can push to it, and keep secrets out of tracked files.
| Action | Requires, when authentication is on |
|---|---|
| View status, diffs, and settings | Access to all workspaces |
| Pull, publish, discard, move, delete, forget, clean up | The above, the developer role or higher, permissions.write_dags, and push_enabled: true |
| Change settings or test the connection | Admin role |
CLI and REST API
dagu sync status
dagu sync pull
dagu sync publish daily-report -m "Update daily report"
dagu sync publish --all -m "Update automation files"
dagu sync discard scripts/generate.py
dagu sync mv scripts/generate.py scripts/render.py
dagu sync delete scripts/render.py -m "Remove report script"
dagu sync forget old-report # drop the record of a missing item
dagu sync cleanup # drop the records of all missing itemsThe commands work on the local server's directories and need git_sync.enabled. See CLI Reference for every flag, and REST API for the /api/v1/sync/* endpoints. In REST paths, URL-encode item IDs: scripts/report.py becomes scripts%2Freport.py.



