Skip to main content

How to Keep Apache Airflow® Files Out of Git with .gitignore

· 5 min read
Jagdish Kumawat
Founder @ Dewiride

When AIRFLOW_HOME is your project folder, Apache Airflow® writes its own files next to your code: a settings file with generated secrets, a database, logs and a file with the admin password. None of them belong in Git, and two of them are secrets. A .gitignore keeps them out before your first commit. This guide writes one on Airflow 3.4.0 and checks that it works.

Syntax​

.gitignore
<file or folder name>
<folder>/
<pattern with *>
LineWhat it ignores
airflow.cfgA file with this name, in any folder
logs/A folder with this name, and everything in it
airflow.db-*Every name that starts with airflow.db-
# ...Nothing: a comment

Git's documentation for .gitignore calls each line a pattern, and says a pattern ending in a slash only matches a folder.

Prerequisites​

  • Git. Check with git --version.

Step 1: See What Airflow Left in the Project​

This project ran airflow standalone once, with AIRFLOW_HOME set to the project folder. It has one Dag in dags. Make it a Git repository and look at the status:

Terminal
git init -b main
git status --short
Output
Initialized empty Git repository in /Users/you/source/airflow-gitignore-demo/.git/
?? airflow.cfg
?? airflow.db
?? dags/
?? logs/
?? simple_auth_manager_passwords.json.generated

The terminal after git init and git status --short: airflow.cfg, airflow.db, dags, logs and simple_auth_manager_passwords.json.generated, all marked ?? as untracked.

?? means untracked: a git add . would add every one of them. Only dags/ is yours:

NameWhat it isIn Git?
airflow.cfgEvery setting, plus a generated fernet_key, [api] secret_key and [api_auth] jwt_secret. Airflow creates it readable only by youNo: it holds secrets
airflow.dbThe SQLite metadata database: runs, users, stateNo
logs/Task and component logsNo
simple_auth_manager_passwords.json.generatedThe admin passwordNo: it's a password
dags/Your Dag filesYes

The .venv folder isn't listed at all: uv puts a .gitignore of its own inside it, containing *, so Git already ignores it.

Step 2: Write the .gitignore​

Create a file named .gitignore in the project folder:

.gitignore
# Python
.venv/
__pycache__/

# Files Airflow creates in AIRFLOW_HOME (this folder). airflow.cfg holds generated
# secrets, so it never goes into Git.
airflow.cfg
airflow.db
airflow.db-*
logs/
simple_auth_manager_passwords.json.generated

The .gitignore file in an editor window: .venv and pycache for Python, then airflow.cfg, airflow.db, airflow.db-*, logs and the passwords file, under a comment explaining that airflow.cfg holds generated secrets.

.venv/ is listed anyway, so it stays ignored if the environment was made by a tool that doesn't add its own .gitignore. __pycache__/ catches Python's compiled files. airflow.db-* catches the extra files SQLite keeps next to the database while Airflow runs.

Step 3: Check It​

Terminal
git status --short
Output
?? .gitignore
?? dags/
Terminal
git status --short --ignored
Output
?? .gitignore
?? dags/
!! .venv/
!! airflow.cfg
!! airflow.db
!! logs/
!! simple_auth_manager_passwords.json.generated

The terminal: git status --short now lists only .gitignore and dags, and git status --short --ignored marks .venv, airflow.cfg, airflow.db, logs and the passwords file with !! as ignored.

The first command now lists only .gitignore and dags/: that's all git add . would take. The second adds the ignored names, marked !!, and every Airflow file is among them.

Common Mistakes​

MistakeWhat happensDo this instead
Committing before writing .gitignoreairflow.cfg and the password are in the historyWrite .gitignore first; if it's too late, change the secrets
Ignoring dags/Your Dags aren't savedIgnore only what Airflow generates
Adding .gitignore after git add .Files already staged stay stagedUnstage them with git rm --cached <file>

Troubleshooting​

SymptomLikely causeFix
A file still shows ??The line doesn't match it, or has a typoCompare the name exactly
An ignored file is in git status as changedIt was committed before you ignored itgit rm --cached <file>, then commit

FAQ​

Should airflow.cfg ever be committed?​

Not this one: it contains the secrets Airflow generated for you. To share settings, use environment variables or a template without secrets.

Is the password file the same as the UI login?​

Yes: it holds the generated password for the admin user.

Conclusion​

After one airflow standalone, git status --short listed four Airflow files next to dags/. Seven patterns in .gitignore left only .gitignore and dags/ to commit, and git status --short --ignored confirmed that airflow.cfg, airflow.db, logs/, the password file and .venv/ are ignored.

Additional Resources​

Apache®, Apache Airflow and Airflow® are either registered trademarks or trademarks of The Apache Software Foundation in the United States and/or other countries. No endorsement by The Apache Software Foundation is implied by the use of these marks.