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?

0

4 Answers 4

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.

Sign up to request clarification or add additional context in comments.

1 Comment

kudos on suggesting to add the files manually. It's just safer and you stay in control.
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.

Comments

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.

Comments

0

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.