- 🧰 Using
tywithgit ls-filesmakes sure only tracked, verified files are checked. - ⚠️ Untracked files often cause false errors when
ty checkruns, especially in CI. - 🔧 Adding
pass_filenames: falseto pre-commit scripts stops scanning files you don't want. - 🤖 Git-aware hooks make
tyintegration easy for all teams and CI pipelines. - 📁 Checking Git tracking status makes sure
tyonly checks clean, committed code.
Ty Check: Ignoring Untracked Files the Right Way
You run ty check, and then you're seeing errors from files you haven't even added to Git yet. Does this sound familiar? When you are busy coding, you shouldn't have to deal with warnings from temporary or half-written files. This guide shows you how to set up ty — a Python type-checking tool — to ignore untracked files by default. Whether you work alone or run pre-commit hooks in a CI/CD pipeline, these steps will help you avoid messy checks and make your Python work smoother.
What Is ty and How Does It Work?
Static type checking has become more and more important in Python development. Tools like mypy, pyright, and pylint are important for making sure types are used correctly. But managing these tools on their own can be annoying, especially when you are getting them to work with your usual tasks. This is where ty comes in.
ty is a tool that combines these utilities into a single, easy-to-use command. Behind the scenes, it usually checks using tools like mypy. It gathers errors and type problems in one standard way. Instead of you having to remember individual command flags or tool names, you can just run:
ty check
What makes ty special is how well it works with Git. Instead of checking every file in your project, ty looks at only the changes in your working directory. This includes files that are:
- Staged for commit
- Modified but not yet staged
- Sometimes even untracked, unless you tell it to exclude them
This close work with Git means you get quick feedback. It also helps with good practices like small, step-by-step typing. And it avoids checking files that don't matter.
The Problem with Untracked Files
By default, ty doesn't tell the difference between tracked and untracked files in the working directory. That can be a big problem.
Imagine you are making a test module or writing a few lines of code in a temporary file. You haven't committed it—or even staged it. But when you run ty check, you get a list of type errors from that file. This causes:
- ❌ CI builds to fail because of unfinished test code
- 🙄 Developers wasting time manually removing errors that don't matter
- 🧪 Extra messages during code reviews, with errors from files not even meant to be committed
Untracked files are often made for a short time or for trying things out on your machine. They might be:
- Not fully typed
- Have syntax errors
- Include code for debugging
- Have unfinished or bad code for experiments
Bringing untracked files into your type-checking tasks goes against the idea of “check only what matters.”
Discussions on forums like GitHub Issues and Stack Overflow are full of complaints about ty finding these temporary files and filling up error logs—especially when used with pre-commit or CI environments.
Understanding Git Status and ty Check Behavior
To fully understand why ty acts this way, let’s look at how it works with Git's inner workings.
Run this in your project:
git status --porcelain
This command gives you a clear, computer-readable view of your repository’s working state. Here’s what it can show:
A– Added filesM– Modified files??– Untracked files
Tools like ty use this information to figure out which files to check. By looking at the output of git status --porcelain, ty can make a list of files it sees as "in progress" or "changing."
But by default, these changes include untracked files.
Even if these files haven’t gone through git add, ty sees them as active unless you specifically stop their inclusion. This is why it's frustrating: a file that isn't ready yet can still be type-checked and cause errors.
Only Check Tracked Files With ty
The best way to fix this? Use Git itself to figure out what files to type-check. Here's the one-liner that helps a lot:
git ls-files | xargs ty
How It Works:
git ls-files: Lists all files that Git is tracking.xargs ty: Passes those files one by one to thetycommand.
This combination makes sure that only committed and staged files—the ones you purposely added to the code—are checked. Temporary, incomplete, or experimental work is left out automatically.
Using ty in this way makes testing more accurate, especially when:
- You are working on several branches at the same time.
- You are changing code with modules that are not finished.
- CI needs a careful, repeatable way to check things.
In DevOps pipelines, this is the main way to control static analysis checks exactly.
Integrating ty with pre-commit Hooks
If your team is using pre-commit (and you really should), it’s important to set up ty correctly in the config to ignore untracked files.
Here’s a recommended part of the config file for .pre-commit-config.yaml:
- repo: local
hooks:
- id: ty-check
name: ty check
entry: bash -c 'git ls-files | xargs ty'
language: system
pass_filenames: false
Key Concepts:
language: systemmakes sure the hook uses your local environment (like Python venv).entryruns a shell command that makes sure only Git-tracked files are checked.pass_filenames: falsestopspre-commitfrom sending its own list of changed files, which might have untracked ones.
This setup helps with:
- More consistent results between local runs and CI environments.
- Easier debugging during hook errors.
- Pre-commit checks that are cleaner and faster, because it scans fewer files that don't matter.
One GitHub contributor said, “Without pass_filenames: false, my notebook drafts caused the build to fail.” Make sure that flag is in place!
CI/CD Benefits of Ignoring Untracked Files in ty
CI/CD pipelines work much better when things are predictable. When running a pipeline, the build environment should check only the code that developers have chosen to put in version control. Here's what you get with this setup:
- ⏱️ Faster build pipelines because it skips temporary or draft files.
- 🔒 Cleaner error logs, with no mess from experimental files or test cases.
- 🔁 Builds that can be repeated and match your local work.
- 🧹 Fewer flaky results or false negatives in type checks.
If your CI tool (like GitHub Actions, GitLab CI, CircleCI) uses your .pre-commit-config.yaml, this method works everywhere. You don't need special settings for each environment.
You can even run:
pre-commit run --all-files
…and be sure that it won't mark your work-in-progress markdown files or local .tmp files.
Creating a Fallback When Git Isn't Available
What happens if you are not in a Git repo? Maybe inside a Docker container, CI job, or short-lived test environment?
No worries. You can handle it smoothly with this bit of code:
if git rev-parse --is-inside-work-tree > /dev/null 2>&1; then
git ls-files | xargs ty
else
ty .
fi
⚙️ This code does a few things:
- It checks if the current directory is part of a Git repo.
- If true, it only checks Git-tracked files.
- If not, it then checks everything in the current directory.
This stops automation scripts from breaking in unusual situations where Git hasn't been set up, like:
- Folders pulled out for deployment
- Secure virtual machines where there are no
.git/folders - CI runners cloning with
--depth=1or with.gitprotection filters.
Common Pitfalls and Mistakes to Avoid
Even if you have followed setup instructions carefully, a few mistakes can make your efforts useless. Watch out for these:
🔄 Forgetting pass_filenames: false
If you leave this out, pre-commit passes changed files—including untracked ones—to your hooks. This brings back the exact problem you are trying to stop.
✅ Staging Incomplete Code
Even tracked files can cause wrong errors if you accidentally stage a module that's only partly typed or broken. Do not run ty after git add until you are sure a file is ready.
🌐 Running ty Globally in CI
Never run ty . in CI without filtering files first. You could end up checking test folders, logs, and helper scripts that don't matter to the main app.
⛔ .gitignore Gone Wrong
Check your .gitignore often. Files like *.tmp.py, examples/, or legacy_code/ should be left out if they cause problems or slow down CI.
Best Practices for a Flawless ty + pre-commit Workflow
Here’s how to make sure your setup works well for a long time and is efficient:
✅ Set Up Your Own Shortcuts
Add this to your shell configuration:
alias ty-safe='git ls-files | xargs ty'
Use ty-safe instead of ty check to make sure checks are clean and only cover what's needed.
✅ Split Hooks by Task
Set up separate pre-commit hooks for:
- Formatting (like
black) - Linting (like
ruff) - Static Checking (like
ty)
This setup, with parts working on their own, makes debugging easier. It also stops them from getting in each other's way.
✅ Test Locally and in CI
Your pre-commit-config.yaml should work in both places. Run:
pre-commit run --all-files
…before each merge. And automate this in CI to keep things the same.
✅ Auto Update Hooks
Keep hooks and their versions up to date with:
pre-commit autoupdate
Do not let your settings get old, as this might bring back older or buggy issues.
✅ Make Tools That Work Well with Git
Organize your projects so that files ty needs are always tracked and committed on purpose. Mark draft or experimental folders to be ignored by Git.
Wrapping Up
By setting up ty to ignore untracked files, you get a cleaner, more reliable experience for development and CI. Whether you are bringing a teammate onto the team, growing your automation, or finding flaky test failures, this small change helps you work faster and with more confidence.
A well-organized setup that works with Git turns static analysis from an annoyance into a quiet, strong helper. It shows only errors you can act on, not distractions. Type safety now works smoothly.
Further Learning and Resources
-
mypy — a static type checker that
tyuses -
black — Python autoformatter
-
ruff — a very fast linter
-
Pre-commit documentation — official guides for use and hooks
-
Try combining aliases like:
alias ty-safe='git ls-files | xargs ty'…to make your workflow and scripts smoother.
Look at other Devsolus tutorials about Python tools, keeping Git clean, and modern CI/CD pipelines for more ways to make things better.
Citations
Stack Overflow. (2023). 2023 Developer Survey. Retrieved from https://survey.stackoverflow.co/2023/
Developer community forums. (2022–2023). GitHub Issues & Discussions Around ty Behavior. Retrieved from https://github.com/
Pre-commit. (2023). Pre-commit documentation. Retrieved from https://pre-commit.com/