Untrack Already Committed Files

Once files are already tracked (committed), simply adding them to .gitignore won’t stop Git from tracking them — you have to remove them from the index while keeping them on disk.


🧩 Step-by-step

1. Make sure your .gitignore is correct

Example:

.obsidian/workspace.json
.obsidian/plugins/obsidian-git/data.json
.trash/
cache/
tmp/

Check it:

1
cat .gitignore

2. Remove ignored files from the index

Untrack them (without deleting locally):

1
git rm -r --cached .

3. Re-add everything (Git will now skip ignored files)

1
git add .

4. Commit the cleanup

1
git commit -m "Remove ignored files from tracking"

5. Push the changes

1
git push

💡 Explanation

  • --cached = remove from the Git index, not from your disk.
  • After this, Git will no longer track or commit those .gitignored files.

✅ Optional checks

See what’s still tracked that shouldn’t be:

1
git ls-files | grep <pattern>

Confirm a file is now ignored:

1
git check-ignore -v path/to/file

🧠 Tip

You can confirm that .gitignore rules work before committing by running:

1
git status --ignored

Only non-ignored files should appear as changes.