How to untrack files (git and git GUI) How to untrack files (git and git GUI) git git

How to untrack files (git and git GUI)


You have to add it to .gitignore and remove it from the git repository so that it stop to track it.

You have 2 possibilities dependending if you still want to keep your files in the working directory or not:

  • If you want to delete the files in your working directory, do git rm.
  • If you want to keep them but just stop to track them, do git rm --cached.

Then, commit this file deletion.


Not sure about your first question as I exclusively use the Git CLI however for your second question try this:

git filter-branch --force --index-filter \'git rm --cached --ignore-unmatch PATH-TO-YOUR-FILE' \--prune-empty --tag-name-filter cat -- --all

Replacing PATH-TO-YOUR-FILE with the actual file name you want to scrub from the history. You should see something along the lines of:

Rewrite 48dc599c80e20527ed902928085e7861e6b3cbe6 (266/266)Ref refs/heads/master was rewritten

If it was successful - After this if you have already pushed to your remote you will need to do a git push --force to overwrite it. Security settings on the branch may deny the push.

Finally for your last question to prevent this happening again add the file in question to your ignore file and git will prevent any tracking from occurring.

The above answer will work however I strongly suggest this approach if the data was sensitive - ie passwords, ssh keys etc as the files will still be in history.

You can read more here https://help.github.com/articles/removing-files-from-a-repository-s-history/ and here https://help.github.com/articles/remove-sensitive-data/.

Hope this helps!

Dylan