-1

Can someone explain the -A flag for git add? (--all, --no-ignore-removal)

I can see in the man pages it says this:

-A, --all, --no-ignore-removal
           Update the index not only where the working tree has a file
           matching <pathspec> but also where the index already has an entry.
           This adds, modifies, and removes index entries to match the working
           tree.

           If no <pathspec> is given when -A option is used, all files in the
           entire working tree are updated (old versions of Git used to limit
           the update to the current directory and its subdirectories).

Would it be correct to translate that to plain English into "it will add files no matter where you are in the directory tree when you are running the command". Would that be okay?

And also, would this mean "simply run git add -A . all the time just to be sure"?

mkrieger1
  • 19,194
  • 5
  • 54
  • 65
Matias Barrios
  • 4,674
  • 3
  • 22
  • 49

1 Answers1

3

This flag has two different behaviors.

One behavior, which is the current default, is to stage both additions and removals. For example, if you run rm Makefile, then with this option (or without this option and without --no-all), Git will stage the removal with git add Makefile. This is more convenient than having to run git add for some paths and git rm for others.

The other behavior, if you don't specify any files to stage, is to stage all files anywhere in the working tree that are modified. This is equivalent to what you've said except that it requires you not to have specified any paths. Note that that doesn't apply if you write git add -A ., since in that case, you've told Git to stage only the working directory and its children. In that case, the -A has only the first behavior (which it would have had anyway unless you're using a very old Git).

If your goal is to stage all changes in the working tree regardless of where you are, simply run git add -A.

bk2204
  • 64,793
  • 6
  • 84
  • 100