Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the 'git add .' ('git add' single dot) command do? [duplicate]

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?

like image 705
chunjw Avatar asked Jun 06 '13 18:06

chunjw


People also ask

What does git add dot command do?

The git add command adds a change in the working directory to the staging area. It tells Git that you want to include updates to a particular file in the next commit. However, git add doesn't really affect the repository in any significant way—changes are not actually recorded until you run git commit .

Does git add add everything?

In Git 2. If you are in any subdirectory of the working directory, git add -A will add all files from the entire working directory, and git add . will add files from your current directory.

Can you git add twice?

This command can be performed multiple times before a commit. It only adds the content of the specified file(s) at the time the add command is run; if you want subsequent changes included in the next commit, then you must run git add again to add the new content to the index.

What does the Git add command do?

The git add command adds new or changed files in your working directory to the Git staging area. git add is an important command - without it, no git commit would ever do anything.

Can I add all files at once in Git?

Being able to shape your history is one of the greatest advantages of using Git. If your commits are too large, contain unrelated changes, or are unclearly described in the commit message, you will lose the benefits of viewing and changing history. By using an option to add all files at once, you may accidentally stage and commit a file.

What is the difference between GIT add * and *?

git add . stages all modified or untracked files in current directory and all subdirectories. git add *.c adds all files with .c extension. * is called "a star wildcard" and it matches any characters. Eg. if you wanted to add any files with extension starting with .c, you could achieve it with git add *.c*.

What does Git add [ filename] do?

git add [filename] selects that file, and moves it to the staging area, marking it for inclusion in the next commit. You can select all files, a directory, specific files, or even specific parts of a file for staging and commit. This means if you git add a deleted file the deletion is staged for commit.


2 Answers

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.

like image 167
agconti Avatar answered Oct 02 '22 03:10

agconti


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

like image 44
Klas Mellbourn Avatar answered Oct 02 '22 05:10

Klas Mellbourn