untrack files in git

Today I learned how to untrack files that have already been added to a git repository. The following command will stop tracking but keep the file there intact. This is good for directories that have auto generated files every so often so everytime you do a git commit, you don’t have to commit a new copy of these files.
git rm --cached filename

The rm made me nervous because I didn’t want to accidentally remove my file ( made a backup before I did it).  Good thing it all worked out and now git doesn’t have to do any unnecessary tracking.

== update ==

Just likes James mentions in the comments, you can use .gitignore as your next step.

This entry was posted in software and tagged , , . Bookmark the permalink.

15 Responses to untrack files in git

  1. Colin says:

    Just what I’ve been lookin for. Thanks

  2. Leandro says:

    Thank you!
    You saved me minutes!

  3. Stefan says:

    Thanks for the google friendly title :)

  4. James says:

    Very helpful, I’ve been wondering how to do that for a while! thank you

  5. Lin says:

    Thanks a lot :)

  6. Yogsototh says:

    Thanks, simple, useful and easier googling than to search the documentation.

  7. Lifesaver, thanks a lot.

  8. Nice! But also if you don’t want to commit autmatically generated directories or files, you could just put them in the .gitignore file. That way you don’t always have to remove them. Unless the naming pattern for your autmatic directories are unpredictable.

  9. Ryan says:

    Funny you mention it James, I’ve had a post about that in my drafts folder for awhile now.

  10. git update-index –assume-unchanged pathtoyourfile

    This command may look less as a workaround.

  11. bauer says:

    Thank You very much for this

  12. mr.wayn says:

    If you do that and then push to a bare and then pull it from bare to another repository. git delete files from that another repository!

  13. Pranil says:

    Hey I’ve got the same problem as mr.wayn, deletes the files from the other repository. Is there a way around this?

  14. Patrick says:

    Take it one step further…place a ‘.gitignore’ file within a directory (example: images/useruploads) and ignore the directory EXCEPT for the .gitignore placed within that directory. This way, when someone pulls your repo, it will create the directory for them but not include all of the files along side.

    The idea is, there must be at least one file within the directory in order for GIT to create the directory.

  15. Michal says:

    Just wrote into URL “git untrack files” thats cool request – response practice :-D

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>