5

Currently, when I want to make a commit and push the content to the remote Git repository, I use:

git add . //<--notice the dot here
git commit -m "some commit message"
git push

I have seen MANY people use git add -A instead. I read the difference between, . and -A, but I am not clear with it.

So are these two commands the same?

If not, when should one use git add . and when git add -A?

sandalone
  • 41,141
  • 63
  • 222
  • 338

4 Answers4

13

git add . adds only the folder you're currently in, git add -A adds all the folders in the repository.

For example if your repo is called foo and you're in the folder foo/bar, and you changed the files foo/file1.pl and foo/bar/file2.pl, git add . would only stage file2.pl while git add -A would stage all files.

On the question of where to use which it depends on your working style: if you keep a clean repo at all times and you only change files which should be committed then you can use git add -A, otherwise it might be wiser to use git add . or even add the files manually. This being said, it's a good idea to always do a git status at the end to make sure you didn't commit something you shouldn't, cause once it's pushed it's hard to obliterate that data.

moscar
  • 355
  • 3
  • 11
  • 1
    kudos on suggesting to add the files manually. It's just safer and you stay in control. – Zloj Jul 05 '16 at 08:08
2
git add -A 

It adds all the files which has changes in all the folders of the repository.

git add .

It adds all the files which has changes in current folder.

1

Since git version 2.0 the default is git add -A

From the release notes:
https://git.kernel.org/cgit/git/git.git/tree/Documentation/RelNotes/2.0.0.txt

git add <path> is the same as git add -A <path> now, so that git add dir/ will notice paths you removed from the directory and record the removal. In older versions of Git, git add <path> used to ignore removals. You can say git add --ignore-removal <path> to add only added or modified paths in , if you really want to.

CodeWizard
  • 128,036
  • 21
  • 144
  • 167
0

git add . adds the changed files from current directory and sub-directories. git add -A adds the changed files from all the directories.

Mohan Kumar P
  • 3,122
  • 1
  • 14
  • 17