Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
+12 votes
3 views
in DevOps and Agile by (29.3k points)

Is there a way to add all files no matter what you do to them whether it be deleted, untracked, etc? like for a commit. I just don't want to have to git add or git rm all my files every time I commit, especially when I'm working on a large product.

3 Answers

+10 votes
by (50.2k points)

To add all files, modified, deleted and untracked then you could use:

git add -A

Note: 

Since git 2.0. The above command will stage all the files in the whole working tree.

If you need to stage the files in your current path you could use:

git add -A .

This will stage files in your current path.

Summary: 

git add -A stages all changes

git add .    stages the new files and modifications but not deletions.

Reference: https://git-scm.com/docs/git-add

+5 votes
by (62.9k points)

Try

git add -u

The "u" option stands for Update.

This will update the repo and really delete files from the repo that you simply have deleted in your local copy.

git add -u [filename]

to stage a delete to just one file. Once pushed, the file can not be within the repo.

Alternatively,

git add -A .

is equivalent to

git add .

git add -u .

Note the additional '.' on git add -A and git add -u. Warning: starting with git 2.0 (mid-2013), this will always stage files on the whole working tree. If you would like to stage files under the current path of your working tree, you would like to use:

git add -A 

0 votes
by (1.3k points)

You see that git add -A or git add. would stage all the changes, including deletions, untracked files within the repository, in one single command. Here is how you do it

To include deletions and new files to be staged with other changes using:

git add -A

To stage changes within the current directory and in all subdirectories using:

git add .

Next you can commit using the command git commit -m "Your message" without necessarily specifying files. It will save your workflow especially with large projects.

Related questions

0 votes
1 answer
0 votes
1 answer
asked Jul 22, 2019 in DevOps and Agile by chandra (29.3k points)
+15 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...