Our development environment uses multiple repositories as part of an overall build system. The build dynamically adapts depending on which repositories you have checked out: if you don't need to build a particular component, just don't clone it.
However, once you have cloned a component, removing it from the build is problematic:
- You can delete the files in the working directory, but
git status
will show uncommitted changes - You can delete the repository, at the expense of re-cloning when you need it again
- You can move the repository, but your multi-repo tools might "helpfully" re-clone
Is there a better way to remove the working directory's files? Something akin to hg co null
or p4 sync ...#none
?
After finding similar questions that didn't quite do what I want, this article provided the answer: create an empty branch.
Of course, ensure you've committed any important files to your repo first. I've called this branch
empty
, but you can give it any name via thecheckout
command.Once set up, you can switch to any branch to get your files back:
When you need to "remove" the working directory, commit your changes, then run:
This removes all tracked files. If you also need to remove untracked files and directories, follow this up with: