[git] Git add all files modified, deleted, and untracked?

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.

This question is related to git git-add git-rm

The answer is


The following answer only applies to Git version 1.x, but to Git version 2.x.

You want git add -A:

git add -A stages All;

git add . stages new and modified, without deleted;

git add -u stages modified and deleted, without new.


This is my alternative (in any bash):

$ git status -s|awk '{ print $2 }'|xargs git add

To reset

$ git status -s|awk '{ print $2 }'|xargs git reset HEAD

For newer version of Git.

I tried git add -A and this prompted,

warning: The behavior of 'git add --all (or -A)' with no path argument from a subdirectory of the tree will change in Git 2.0 and should not be used anymore. To add content for the whole tree, run:

git add --all :/ (or git add -A :/)

To restrict the command to the current directory, run:

git add --all . (or git add -A .)

With the current Git version, the command is restricted to the current directory.


Then I tried below which worked.

git add --all :/

I authored the G2 project, a friendly environment for the command line git lover.
Please get the project from github - G2 https://github.com/orefalo/g2

It has a bunch of handy commands, one of them being exactly what your are looking for: freeze

freeze - Freeze all files in the repository (additions, deletions, modifications) to the staging area, thus staging that content for inclusion in the next commit. Also accept a specific path as parameter


Try:

git add -A

Warning: Starting with git 2.0 (mid 2013), this will always stage files on the whole working tree.
If you want to stage files under the current path of your working tree, you need to use:

git add -A .

Also see: Difference of git add -A and git add .


git add --all or git add -A or git add -A . Stages All

git add . Stages New & Modified But Without Deleted

git add -u Stages Modified & Deleted But Without New

git commit -a Means git add -u And git commit -m "message"

After writing this command follow these steps:-

  1. press i
  2. write your message
  3. press esc
  4. press :wq
  5. press enter

git add <list of files> add specific file

git add *.txt add all the txt files in current directory

git add docs/*/txt add all txt files in docs directory

git add docs/ add all files in docs directory

git add "*.txt" or git add '*.txt' add all the files in the whole project


Try

git add -u

The "u" option stands for update. This will update the repo and actually delete files from the repo that you have deleted in your local copy.

git add -u [filename]

to stage a delete to just one file. Once pushed, the file will no longer be in the repo.

Alternatively,

git add -A .

is equivalent to

git add .

git add -u .

Note the extra '.' 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 want to stage files under the current path of your working tree, you need to use:

git add -A .

Also see: Difference of git add -A and git add .


I'm not sure if it will add deleted files, but git add . from the root will add all untracked files.


From Git documentation starting from version 2.0:

To add content for the whole tree, run:

git add --all :/

or

git add -A :/

To restrict the command to the current directory, run:

git add --all .

or

git add -A .

I use the following line to add for staging all the modified and newly created files, excluding the ones listed in .gitignore:

git add $(git ls-files -mo --exclude-standard)

(the syntax $() is for the bash shell). I guess that the command line option -mod should add also the deleted files... Or, if you have file names with embedded blanks, the following one-liner should do the trick:

git ls-files -z --deleted --modified --others --exclude-standard | xargs -0 git add

Examples related to git

Does the target directory for a git clone have to match the repo name? Git fatal: protocol 'https' is not supported Git is not working after macOS Update (xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools) git clone: Authentication failed for <URL> destination path already exists and is not an empty directory SSL_connect: SSL_ERROR_SYSCALL in connection to github.com:443 GitLab remote: HTTP Basic: Access denied and fatal Authentication How can I switch to another branch in git? VS 2017 Git Local Commit DB.lock error on every commit How to remove an unpushed outgoing commit in Visual Studio?

Examples related to git-add

Fix GitLab error: "you are not allowed to push code to protected branches on this project"? Git add all subdirectories Staging Deleted files Adding Only Untracked Files Add all files to a commit except a single file? Git add all files modified, deleted, and untracked? Difference between "git add -A" and "git add ." Removing multiple files from a Git repo that have already been deleted from disk How can I add an empty directory to a Git repository?

Examples related to git-rm

Remove a folder from git tracking Staging Deleted files Why are there two ways to unstage a file in Git? How to remove multiple deleted files in Git repository "git rm --cached x" vs "git reset head --? x"? Git: list only "untracked" files (also, custom commands) Git add all files modified, deleted, and untracked? Git: How to remove file from index without deleting files from any repository How to revert a "git rm -r ."? How can I delete a file from a Git repository?