In the context of DevOps, you can use the git untrack files to remove the sensitive files which you have mistakenly incorporated into the repository. This particular process can be done by using the “git rm - - cached” command. Here are the steps given for this specific objective:-
Untracked files
# Remove files from being tracked by Git, but keep them in the local directory
Git rm –cached …
You can replace “file1” and “file2” etc with the real names of your files that you want to be untracked. This specific command will help you remove the files from the staging area and therefore it will start tracking changes to them without deleting them from your local directory.
Updating Gitignore
Once the untracking process of sensitive files is completed, now it is compulsory to add their filenames and patterns to the git ignore file so that it cannot track them again accidentally.
# Open .gitignore in a text editor and add sensitive file names or patterns
Nano .gitignore
Inside Gitignore add the file names or patterns of the sensitive files that you have untracked previously. For example
# Ignore sensitive files
Filename.txt
Sensitive_folder/
*.log
Save the “gitignore” file as it will ensure that git will ignore these files and won’t consider them for version control or even staging.