Get all files that have been modified in git branch
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
When you ask Git for “all files modified in a branch,” the first thing to clarify is compared to what. Git does not store a branch as a separate file list. A branch is just a pointer to a commit, so changed files are always computed relative to another commit, branch, or merge base.
In practice, the most common question is: which files differ between my branch and main? Once that comparison target is clear, the command is straightforward.
The Usual Branch-to-Branch Command
To list file names changed between your current branch and main, use:
The triple-dot form matters. It compares HEAD against the merge base with main, which is usually what you want for “changes introduced by this branch.”
If you are currently on the feature branch, this is a good default review command.
Why Triple-Dot Is Often Better
Git supports both double-dot and triple-dot comparisons, and they mean different things.
- '
main..featurecompares the end commits directly' - '
main...featurecompares the feature branch against the common ancestor'
For branch review, triple-dot is usually more accurate because it shows what the branch introduced since it diverged.
If you use double-dot carelessly after main has moved forward, you may get a file list that reflects unrelated history differences too.
List Modified Files in the Working Tree
Sometimes the question is not about committed branch history. Sometimes you just want currently changed files in your checkout.
Use:
Or only the names of tracked modified files:
That shows changes in your working tree relative to the index or HEAD, depending on how you call it.
Include Only Files Changed by Branch Commits
If you want the set of files touched by commits reachable from your branch but not from main, another useful command is:
This is conceptually similar to triple-dot diff and makes the merge base explicit.
It is especially helpful when you want a scriptable or debuggable formulation of the comparison.
Use git log When You Care About Commit History Too
If you also want to see which commits changed which files, use:
This is not just a file list. It is a history view that can help answer a slightly different question: not only what files changed, but which commits touched them.
That is useful during code review or when investigating why a file appears in the diff at all.
Filter for Added, Modified, or Deleted Files
Sometimes you want only certain change types.
This example includes only added and modified files, excluding deleted ones.
Useful filters include:
- '
Afor added' - '
Mfor modified' - '
Dfor deleted' - '
Rfor renamed'
A Typical Review Workflow
A common branch-review sequence looks like this:
That ensures you compare against the current remote-tracking branch instead of an outdated local main.
Common Pitfalls
A common mistake is asking for changed files “in a branch” without specifying the comparison target. Git always needs a baseline.
Another mistake is using double-dot when you really want the merge-base view. For feature-branch review, triple-dot is usually the better choice.
Developers also forget to git fetch first, then wonder why the file list differs from what the hosting platform shows in a pull request.
Finally, do not mix up working-tree changes with branch-history changes. git status and git diff main...HEAD answer different questions.
Summary
- Branch file changes are always relative to another commit or branch.
- For “what did this branch change compared to main,” use
git diff --name-only main...HEAD. - Use triple-dot for feature-branch review because it compares from the merge base.
- Use
git statusor plaingit diff --name-onlyfor current local modifications. - Fetch the latest remote state before comparing if you want results that match code review tools.
Related reading
- Get changes from master into branch in Git
- Get changes from master into branch in Git
- Get source JARs from Maven repository
- Get the creation date of a stash
- Get the current git hash in a Python script
- Get the short Git version hash
- Getting current branch and commit hash in GitHub action
- getting fatal not a git repository '.' when using post-update hook to execute 'git pull' on another repo
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.