Skip to main content

Section C.3 Git Has Been Updating Files, But Now I Don’t Want It To

This is actually pretty common. Maybe you are writing a book and your abandoned chapters were on GitHub for your editors to look at. Now that the book is published, you don’t want those chapters online. Maybe you are using an API and when you were developing a project had your app’s API connection keys available and not that the project is public you want to remove the file containing them.
When Git is keeping track of files, we say that it is tracking files. Untracking files is not super difficult, but does, like all Git commands, require the command line.

Warning C.3.0.1.

Untracking files from Git does not delete them from your local computer. However, the next time you push to GitHub, they will no longer be there. Thus, the next time your collaborators pull from the repository, their copy of the file will be deleted.

(a)

Identify the files you wish to remove from Git’s tracking service

(b)

Use git rm --cached <filename>. You may also add multiple files as done with git add (Git Procedure 4.5).

(c)

Want to untrack folders? You will need the -r recursive option. So, git rm -r --cached <folder-name> will do the trick.

(d)

The above options will not delete the file(s)/folder(s) from your local computer. If you would like the files deleted and untracked, use the above commands with out the --cached feature: git rm <filenames> and git rm -r <folder-names>.