Take the 2-minute tour ×

I ran "git status" and listed below are some files that were modified/or under the heading "changes not staged for commit". It also listed some untracked files that I want to ignore (I have a ".gitignore" file in these directories).

I want to put the modified files in staging so I can commit them. When I ran "git add .", it added the modified files AND the files I want to ignore to staging.

How do I add only the modified files and ignore the untracked files if presented with the git status below.

Also, are my ".gitignore" files working properly?

$ git status
# On branch addLocation
# Changes not staged for commit:
#       modified:   someProject/path/domain/viewer/LocationDO.java
#       modified:   someProject/path/service/ld/LdService.java
#       modified:   someProject/path/service/ld/LdServiceImpl.java
#       modified:   someProject/path/web/jsf/viewer/LocationFormAction.java
#       modified:   someProject/war/WEB-INF/classes/message/viewer/viewer.properties
#       modified:   someProject/war/page/viewer/searchForm.xhtml
# Untracked files:
#       .metadata/
#       someProject/build/
share|improve this question
add comment

3 Answers

up vote 126 down vote accepted

Ideally your .gitignore should prevent the untracked ( and ignored )files from being shown in status, added using git add etc. So I would ask you to correct your .gitignore

You can do git add -u so that it will only stage the modified files.

You can also do git commit -a to commit only the modifications.

Note that if you used git add ., then you would need to use git add -u . (See "Difference of “git add -A” and “git add .").

share|improve this answer
point of interest, this (add -u) doesn't add only modified files, it also "adds" deleted ones.. something I'm currently trying to prevent. –  Zach L Jan 16 '13 at 21:44
Zach any solution yet? only adding modified files? –  Kilian Lindberg May 28 at 13:17
add comment

You didn't say what's currently your .gitignore, but a .gitignore with the following contents in your root directory should do the trick.

share|improve this answer
I was using my .gitignore all wrong. I had an empty .gitignore file in every directory that I wanted to ignore instead of having a single gitignore with contents in it. –  Steve Aug 19 '11 at 18:43
@Steve: This would work if each .gitognore contained a start (ignore everything). But a single .gitignore in the top directory is usually much simpler to use and suffices. –  maaartinus Jan 23 at 8:01
add comment

This worked for me:


git add `git status | grep modified | sed 's/\(.*modified:\s*\)//'`
share|improve this answer
add comment

Your Answer


