20

I was in the past using this Git command for my files:

add --update :/ 

as someone told me this was the best way to pick up all the files that had been added, deleted and updated.

However after reading: Difference between "git add -A" and "git add ."

I think maybe I should be using git add -A

Can someone tell me if there's a difference and what git add --update :/ actually does?

mkrieger1
  • 10,793
  • 4
  • 39
  • 47
Alan2
  • 19,668
  • 67
  • 204
  • 365

1 Answers1

33

git add --update :/ will update or remove previously tracked files from the entire working tree. It will not add new files.

git add -A will also update, remove previously tracked files, but it will also add new files. As this command doesn't have the explicit pathspec of :/ that your update command does, depending on your version of git, this may be for all files in the entire working tree, or it may be for the current directory and all subfolders and files.

For more info, the docs for git add can be found: http://git-scm.com/docs/git-add

Charlie
  • 6,696
  • 1
  • 35
  • 44
  • so from what you are saying I assume that it would be better for me to use git add -A as that seems to cover everything? – Alan2 Jan 26 '15 at 11:57
  • Better is very subjective. If you want to easily catch additions and you have all of your .gitignore files setup correctly so that you don't accidentally commit any secrets to the repository (at least that shouldn't be committed), and your git version is new enough then -A fits your use case better yes. If those things but not git version, `git add -A :/` might be better (unless you only want to commit from your current directory lower, then `git add -A .`) – Charlie Jan 26 '15 at 12:52
  • 1
    @Charlie, what do you mean by the `previously tracked files`? – hellouworld Mar 20 '20 at 14:09
  • 1
    @hellouworld Files in your working directory can be tracked or untracked... See: https://git-scm.com/book/en/v2/Git-Basics-Recording-Changes-to-the-Repository since git add is the mechanism to change a file from untracked to tracked, I suspect 5 years ago I was trying to emphasize the state of files in relation to git *before* running the add commands... – Charlie Mar 20 '20 at 14:15
  • Good answer; just clarifying that you can also add a pathspec in the second case (`git add -A `, although the questioner did not include it. – John Aug 14 '20 at 21:16