Skip to content
GreenSnippets

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
base="${1:-origin/main}"

git diff --name-only --diff-filter=ACMR -z "$base"...HEAD -- '*.ts' '*.tsx' \
  | xargs -0 --no-run-if-empty npx eslint

Example / expected output

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.