10 months ago

Ignoring a previously committed file quickly

Files already tracked by Git are not effected by the .gitignore file.

If you want to ignore a file that you've committed in the past,

  • Use echo with >>(double redirection arrow) to append a relative file path to your .gitignore directly from the terminal.
  • Use git rm with the --cached option to delete the file from your remote repository, but keep it in your working directory as an ignored file.
  • Commit.
$ echo debug.log >> .gitignore
$ git rm --cached debug.log
rm 'debug.log'
$ git commit -m "Start ignoring debug.log"
Do you have any comment on this tricks? then let the author know about that. comment here