Skip to content

Instantly share code, notes, and snippets.

@edheltzel
Last active October 31, 2019 23:36
Show Gist options
  • Save edheltzel/c4eeb594759056b1df05c39af61b1a27 to your computer and use it in GitHub Desktop.
Save edheltzel/c4eeb594759056b1df05c39af61b1a27 to your computer and use it in GitHub Desktop.
Untrack files already added to git repo

Step 1 - Commit all changes

Make sure all changes are commited including the .gitignore

Step 2 - Remove everything from the repo

To clear the repo, use: git rm -r --cached .

  • rm is the remove command
  • -r will allow recursive removal
  • --cached will remove files from the index. (Your file will still be there)
  • . indicates that all files will be untracked.
    • Untracking a specific file use: git rm --cached foo.txt

The rm command can be unforgiving. If you wish to try what it does beforehand, add the -n or --dry-run flag to test.

Step 3 - Re add everything

git add .

Step 4 - Commit

git commit -m '.gitignore fix'


source: http://www.codeblocq.com/2016/01/Untrack-files-already-added-to-git-repository-based-on-gitignore/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment