If you use Git, you're probably adding files all the time as you develop your project out further and further. Sometimes though, you might need to actually remove a file from the Git repository but not not from your local files. For example, say you forgot to add a file to .gitignore
but you don't want to remove it from your local development environment. This could be from a mistake or you didn't realize that a new package or something created a bunch of nasty log files you don't want in the repo. Either way, this is actually very easy to do.javascript
This method will remove a single file from your Git repository without deleting the file from your local environment. Then when you run git push
, the files will be removed in the remote repo.java
git commit -m 'untrack file from git'
git push # remove this file from remote repository git rm --cached filexample.txt
In a similar fashion, you can do this for multiple files at one time.git
git rm --cached file1.txt file2.txt file3.txt
This also works recursively for folders so long that you add the -r
flag to the command. Here's an example:
this
git rm -r --cached folder https://scotch.io/tutorials/how-to-use-git-remove-without-deleting-the-files