Assume that, you have committed and pushed a file thelinuxfaq.txt or any directory node_modules to the Git repository and if you want to ignore that file or not required to keep on the remote repository,
To ignore a file that has already been committed to a Git repository, you will need to delete the file from your repository and then add a rule to your .gitignore file to ignore the file in the future. Here are the steps to do this:
Remove the file from your repository by running the following command:
Add the file to your .gitignore file so it will be ignored in the future.
Commit your changes to the repository:
Note: Add "-r" after "rm" if you want do it for the directory
Add the file / path into .gitignore file and do this.
Push your changes to the remote repository:
Below is full steps to remove a directory or file path "nodejs_app/node_modules" from git repo, assume that I've used the project/git repo root path.
git rm --cached -r nodejs_app/node_modules
git rm --cached -r thelinuxfaq.txt
git commit -m "remove the node_module and a thelinuxfaq.txt"
echo "/apk/android_app/node_modules" >> .gitignore
git add .gitignore
git commit -m "Adding node modules and thelinuxfaq.txt to git ignore"
Keep in mind that this will remove the file from the repository for all users. If you want to keep the file locally but ignore it for everyone else,
you can simply add the file to your .gitignore file and leave it in the repository.