How can I go through with the untracking files for removing files from version control?

142    Asked by Daminidas in Devops , Asked on Jan 15, 2024

 I am currently collaborating on a project with a team by using the git technology and I have mistakenly added some sensitive files to my repository. Now, I want to remove all these files from the version control system without deleting them from my local directory and without negatively to other collaborators. So my question is how can I use the process of untracking files in the git technology for this particular purpose? 

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

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.

Your Answer


Parent Categories