I read the original question as wanting to preserve the repo, but delete the working tree. This is useful when you want to put a project on the backburner, after some work has been done with it.
One solution is to create a branch with an empty working tree, and check out the empty branch:
git checkout --orphan archived
git reset --hard
git commit -m "Project is archived" --allow-empty
Explanation:
git checkout --orphan archived
creates the branch archived
, with unrelated history to the project.
git reset --hard
removes versioned files that exist in the working tree. It preserves unversioned files, which can be cleaned out with git clean -fd
if necessary.
git commit -m "Project is archived" --allow-empty
creates a commit with no files on the archived
branch.
Unlike the git clone -n
option, this method:
- does not leave the index showing all files as "deleted"
- unambiguously documents what happened to the work tree. The current branch name will be "
archived
"
A repo thusly 'archived' is ready to be re-activated by git checkout master
, and can subsequently be re-archived with git checkout archived