Reputation: 9
The remote repository has thousands of files, but I only work with a few. How do I delete all unnecessary files (from git and folder) from the local repository, but not from the remote repository? Thanks for the help!
Structure of the repo:
A/
AA/
aa1.code
aa2.code
...
B/
bb1.code
...
root1.code
root2.code
...
... I need (for example) only files root1.code and A/AA/aa1.code
Upvotes: 0
Views: 456
Reputation: 115017
You can use Sparse Checkouts to only checkout the files you need.
git clone --no-checkout remote
git sparse-checkout init --cone
git sparse-checkout set <path1> <path2> ...
There is a very new option to clone with a filter, that way your .git
older will be limited to only the files and history you want. Checkout the link for a very extensive answer over on the unix stackexchange. It looks like ---filter
must be supported by your git remote.
git clone --no-checkout --filter=blob:none remote
git sparse-checkout init --cone
git sparse-checkout set <path1> <path2> ...
More details in this blog post with a couple of great examples on how to setup your sparse checkout configuration.
Upvotes: 3
Reputation: 31
The quick answer is you can't do that. The repository is the repository. If you delete files locally, they will be deleted on the remote server when you push your changes.
There are probably ways of hacking around the problem, but wouldn't be advisable. For example, you could have your own local branch and use some sort of IDE solution in that branch, the project structure of which only displays the files you want. This would be possible in something like Visual Studio, but of course you wouldn't be able to compile them without dependencies.
Upvotes: 2
Reputation: 84
In my opinion you have to copy the entire directory to work with the files. So it is not possible to delete them, because the next pull request would copy them again to your local clone.
Maybe use something like sub-directories in git.
Upvotes: 0