How to Stop Tracking and Start Ignoring in Git

  1. Ignoring changes to a file
  2. What is Git Repository
  3. What is the git rm Command
  4. What is a .gitignore File

The files that were ignored are tracked in a file, are named .gitignore. You have an opportunity to add file paths and directory paths that you don’t wish to be tracked by Git in this file. Almost all programmers, working with Git, are eager to learn how to stop tracking files, which were already inserted into a git repository. This snippet is aimed at explaining the process of stopping to track and ignoring changes to a file in Git. The .gitignore will prevent untracked files from being added to the set of files tracked by Git, however, Git will continue to track the files that are already being tracked.

Ignoring changes to a file

The following command keeps the local file for you, but it will be deleted when someone pulls it:

git rm --cached <file-name>


git rm -r --cached <folder-name>

The next command is for optimization, like a folder containing a lot of files. It instructs Git to stop checking that folder every time for changes, as it won't have any. The assume-unchanged index will be reset, and files will be overwritten if there are upstream changes to the file or folder when you pull:

git update-index --assume-unchanged <path-name>

The following command will instruct Git that you need your own independent version of the file or folder:

git update-index --skip-worktree <path-name>

What is Git Repository

Git repository serves as special storage for the files of your project. With git repository, it is possible to save the versions of your code, as well as, to have access to them. If you want to create a new git repository, you need to run the git init command. It is used once to initialize a new repository. Another one-time operation is the git clone command, with the help of which you can create a clone of an existing repository.

What is the git rm Command

The git rm command can remove particular files or a group of files from a git repository. You can also use it to remove files from the working directory and the staging index. But it is not possible to remove a file only from the working directory. The git rm command doesn’t remove branches either.

What is a .gitignore File

Generally, Git classifies the files of the working copy as 3 things:

  • A tracked file - the one that has been committed or staged before;
  • An untracked file- the one that has not been committed or staged before;
  • An ignored file- the one that has been commanded to be ignored.

In your working copy, the files are visible for git as untracked, tracked or ignored. Ignored files are those you told Git to ignore. In case you want to commit this kind of files, you should derive them from the repository source. The ignored files are stored in the file called .gitignore. There is no git ignore command, hence you should edit and commit these files by hand.

Do you find this helpful?

Related articles