ShareYourGroupShareYourGroupGit Help

Stop tracking a file but keep it on disk

I added a file that should be in .gitignore.

The problem

I added a file that should be in .gitignore.

How the practice repository looked before

$ git status --short --branch
## main
$ git log --oneline -5
0087477 Oops, local config
611de33 Add line two
fec9a16 Add notes

The fix

$ git rm --cached config.local
rm 'config.local'
$ edit .gitignore
config.local
$ git add .gitignore
(no output: that is normal)
$ git commit -m "Stop tracking local config"
[main 4746bec] Stop tracking local config
 2 files changed, 1 insertion(+), 1 deletion(-)
 create mode 100644 .gitignore
 delete mode 100644 config.local

Check the result

$ git status --short
(no output: that is normal)
$ git ls-files
.gitignore
notes.txt

Why this works

git rm --cached removes the file from Git but leaves it in your folder. The .gitignore line then keeps it from being added again.

If this is not quite your case

Other people who pull this commit will have the file removed from their folders, because Git applies the deletion. Tell them to keep a copy if they need it. For a folder, add -r: git rm -r --cached folder.

Be careful: The old commits still contain the file. If it held a real password, change the password; removing it from history needs a separate tool.

This is an independent guide. It is not connected with the Git project, GitHub, GitLab or any company named here. Every command below was run on 14 November 2026 with the real program (git version 2.56.0.windows.4) in a new empty practice repository; the output shown is what it printed. Facts about options were read in the official Git documentation on 14 November 2026.