83

I don't get what the Git command means, when adding files to the stage with the use of a period (or full stop, single dot):

$ git add .

What does this do?

Rounin
  • 27,134
  • 9
  • 83
  • 108
chunjw
  • 919
  • 1
  • 8
  • 8
  • 1
    The period in `git add .` means the current directory and all files within it, recursively. (The asterisk in `git add *`, on the other hand, would mean all files in the current directory except ones that begin with a period.) – nCardot Jun 12 '21 at 04:07

4 Answers4

98

git add . adds / stages all of the files in the current directory. This is for convenience, and can still be used if you have certain files you don't want to add by using a .gitignore

A tutorial for .gitignore is located here.

A deeper look into git add . vs git add -A vs. git add -u is located here and it might answer your question if you wanted more control of how you add all of the files / wanted to know how git add . works.

Community
  • 1
  • 1
agconti
  • 17,780
  • 15
  • 80
  • 114
36

git add . adds all modified and new (untracked) files in the current directory and all subdirectories to the staging area (a.k.a. the index), thus preparing them to be included in the next git commit.

Any files matching the patterns in the .gitignore file will be ignored by git add.

If you want to skip the git add . step you can just add the -a flag to git commit (though that will include all modified files, not just in the current and subdirectories).

Note that git add . will not do anything about deleted files. To include deletions in the index (and the comming commit) you need to do git add -A

Klas Mellbourn
  • 42,571
  • 24
  • 140
  • 158
4

It adds all subsequent resources (on which you have made changes) under that folder to Git's version control for commit.

You should learn Git from this excellent walkthrough: Resources to learn Git

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Lenin
  • 570
  • 16
  • 36
0

In current versions of Git, this recursively adds all new, modified, and deleted files in the current directory to the index.

The period (.) is the standard way to refer to the current directory in many file systems (by contrast, ".." refers to the parent directory). The add Git command adds the file contents to the index. So git add . recursively adds all files in the current directory to the index.

As of Git 2.0 (added in 2014, a year after the question was asked), this will include new, modified, and deleted files. Previous versions of Git did not include deleted files:

Note that older versions of Git used to ignore removed files; use --no-all option if you want to add modified or new files but ignore removed ones.

M. Justin
  • 14,487
  • 7
  • 91
  • 130