Getting Git

A comprehensive video course from git init to Git Master.

Master: git rm


In this video we'll Master git rm

In the init video we used git rm to remove a file from the Git repository and the file system.

There are times where you might want to remove the file from the Git repository, but keep your local copy.

Said another way, you want to remove the file from version control, but not delete the file.

In these cased, you can use the --cached option.

Let's demonstrate this with File 3 by running:

git rm --cached file-3.txt

Now when we run git status we see the file has been marked as deleted, but also the file also appears as untracked.

While it might seem odd the file is listed twice, it reminds us the Git repository is not the same as the file system.

In this case, we are removing the file from version control. So this command is effectively the opposite of git add.

However, since we used the --cached option we did not delete the file locally.

So now Git sees it as a new, untracked file just as it did before using git add.

Although you might not use the --cached option very often, understanding the boundaries between the Git repository and the file system is important for mastering Git.