Search code examples
gitarchivegit-clone

Remove files from disk but keep Git clone directory; archive local repo


User-Story

Say I've cloned a project and pushed my work and I'm done with it for now. I expect I may need to go back to it, so I'd like to keep the clone locally to quickly switch back, but there is also a chance I am done for good, so I'd like to dump the files from disk.

Question

Is it possible to do this? To "archive" the local repo so I only keep the directory and .git dir and git understands this state when running commands like git status?

[EDIT:] The main reason for this question is so I can be lazy and not have to go find the repo URL to re-clone when I go back to work. This is really not a critical need but it could be pretty handy.


Solution

  • tar/zip seems to be the best workaround:

    • Effectively removes the files from IDEs/search/grok. Disk wasn't really an issue but this is a lot smaller.
    • Does not lose the origin URL so after unzipping there is nothing needed to begin working again, aside from pulling any updates.

    Here is a guide randomly yanked from the net.

    This is just a simple workaround. If you are after something more like a backup, especially if the plan is to transfer the files, see @VonC's answer.