122

What's the difference between:

  • git add .
  • git commit -a

Should I be doing both, or is that redundant?

Mikhail
  • 7,749
  • 11
  • 62
  • 136
Yarin
  • 173,523
  • 149
  • 402
  • 512
  • 2
    see also (not exact duplicate, though): http://stackoverflow.com/questions/572549/difference-of-git-add-a-and-git-add – CB Bailey Aug 22 '10 at 13:37

3 Answers3

162

git commit -a means almost[*] the same thing as git add -u && git commit.

It's not the same as git add . as this would add untracked files that aren't being ignored, git add -u only stages changes (including deletions) to already tracked files.

[*] There's a subtle difference if you're not at the root directory of your repository. git add -u stages updates to files in the current directory and below, it's equivalent to git add -u . whereas git commit -a stages and commits changes to all tracked files.

CB Bailey
  • 755,051
  • 104
  • 632
  • 656
15

git commit -a automatically invokes git add on all files it knows about. You can use git add to select what files to commit. Consult the docs for more info: here

Kasun Siyambalapitiya
  • 3,956
  • 8
  • 38
  • 58
alternative
  • 12,703
  • 5
  • 41
  • 41
2

By using the git commit -a switch with the commit command to automatically "add" changes from all known files (i.e. all files that are already listed in the index)

Dilip
  • 21
  • 2