Rafe
Rafe

Reputation: 2065

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.

Upvotes: 0

Views: 324

Answers (3)

Rafe
Rafe

Reputation: 2065

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.

Upvotes: 0

VonC
VonC

Reputation: 1329652

Instead of an archive, I would use git bundle

That will create one file, with the full repository history in it: you can easily back it up somewhere.
And you can clone your repository back from that one file.

You can make a script which would:

  • create a bundle
  • and generate a second script able to:

That way, you have two files to backup:

  • the Git repository as a bundle
  • the (generated) script able to clone and restore the remote origin URL once cloned from the bundle

Upvotes: 1

tmaj
tmaj

Reputation: 35155

Here are some options:

  1. (Preferred) Delete the folder and clone again when needed. You will need to pull when you start work again anyway. There is no much benefit in storing a stale copy.
  2. Keep the folder the way it is.
  3. Zip the folder if you want to save space.

Upvotes: 1

Related Questions