How would you stop tracking future changes in an existing Git repository file, but do not want to delete that file from the repository?
git rm --cached
is the command that’ll do the trick, however, it needs to be done in following way.
Syntax
git rm --cached filename
Steps with example
Update the .gitignore
file to include the filename, stage and commit .gitignore
file.
ak@--mac git-useful-commands % echo "db.config" >> .gitignore
ak@--mac git-useful-commands % git add .gitignore
ak@--mac git-useful-commands % git commit -m "Update .gitignore"
Now make some edits and stage the file that you want to remove from future tracking. Later, remove the file from staging and commit it
ak@--mac git-useful-commands % git add db.config
ak@--mac git-useful-commands % git rm --cached db.config
ak@--mac git-useful-commands % git commit -m "untrack db config file"
Now, the file will remain in the repository, but future changes won't be tracked.
Happy Coding!
Top comments (0)