8

What is the difference between "git add" and "git update-index"?

Under what circumstances would I use one of these commands or the other?

jpd
  • 683
  • 5
  • 8

2 Answers2

6

Basically, update-index is a plumbing command - it means, low-level. git add internally uses update-index. I believe, that

git add <file> is the same as git update-index --add <file>

One of the circumstances, when I use update-index, is when you have a change to a file, which you don't want to commit - in this case you can run

git update-index --assume-unchanged <file>

So if you run git status after that, you'll see, that file not in the list of changed files.

More here How to manage configuration files when collaborating?

and here http://gitready.com/intermediate/2009/02/18/temporarily-ignoring-files.html

Community
  • 1
  • 1
berliner
  • 1,887
  • 3
  • 15
  • 23
4

To quote git help update-index:

See also git-add(1) for a more user-friendly way to do some of the most common operations on the index.

So git add is the thing you normally use, while git update-index is the more powerful variant that also requires more knowledge on your side.

NB. It really pays off to get used to the git help command, the help pages of git are excellent.

AnoE
  • 8,048
  • 1
  • 21
  • 36