2

The documentation for git-rm contains this short description:

git-rm - Remove files from the working tree and from the index

What exactly is meant by the working tree and the index, and which local or remote files will be removed?

Christian Gollhardt
  • 16,510
  • 17
  • 74
  • 111
Joshua Lee
  • 45
  • 8
  • You might find some help at [this question about HEAD, working tree, and index](http://stackoverflow.com/q/3689838/18356). – shoover Mar 29 '17 at 22:39
  • The working tree and the index are fundamental concepts in Git. You should find a good Git tutorial. – Keith Thompson Mar 30 '17 at 01:50

2 Answers2

3

The "working tree" is your checkout of the files sitting on disk.

The "index", "staging area", or "cache" (you'll see it referred to as all three) is internal to Git. It's the space you prepare the next commit. When you git add you're copying the files from the working tree to the staging area. When you git commit you're committing what's in the staging area.

git rm removes files from both the working tree and the staging area (unless you tell it to just remove from the staging area with --cached).

This cheat sheet might help you understand the relationship between the working tree, staging area, and HEAD (the currently checked out commit). More importantly, it tells you how to manipulate them because the commands are really not-intuitive.

Schwern
  • 153,029
  • 25
  • 195
  • 336
0

It means removing from working tree: the working directory of your file system tree where you cloned this repository and from index in .git directory maintained by git. git rm will never remove the file from working directory alone otherwise it will leave index database in inconsistent state. To inform index database about removal of files using Unix based rm command, you're required to run git commit -a which essentially removes the index of deleted objects.

Vishal Sahu
  • 650
  • 12
  • 23