List files changed compared with main
Get the files added, copied, modified or renamed on your branch, useful for linting or testing only what changed.
- Bash
- GreenSnippets
- MIT
base="${1:-origin/main}"
git diff --name-only --diff-filter=ACMR -z "$base"...HEAD -- '*.ts' '*.tsx' \
| xargs -0 --no-run-if-empty npx eslintExample / expected output
# Lints only the TypeScript files changed on this branch.How it works
git diff --name-only main...HEAD (three dots) compares against the merge base, so it shows only your branch's own changes even if main has moved on. --diff-filter=ACMR excludes deleted files, which you cannot lint. Use -z and xargs -0 for names with spaces.
This snippet has been reviewed but was not executed by an automated test. Test it in your own environment before relying on it.
Related snippets
- Bash
Retry a shell command with backoff
Re-run a flaky command a few times with increasing delays and a clear failure exit code.
- Bash
Parse command-line flags with getopts
Handle -v, -o FILE and -h in a bash script with getopts and a usage message.
- Bash
Run commands in parallel with xargs
Process many files concurrently with xargs -P, safely handling spaces and newlines in names.
- Bash
Timestamped logging functions for scripts
Small log, warn and die helpers that write ISO timestamps to stderr and keep stdout clean for data.

